Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 68b5338189 |
78
dal/dal.go
78
dal/dal.go
@ -6,21 +6,20 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
_ "github.com/ClickHouse/clickhouse-go"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||||
"gitea.pena/SQuiz/common/repository/account"
|
"gitea.pena/SQuiz/common/repository/account"
|
||||||
"gitea.pena/SQuiz/common/repository/amo"
|
"gitea.pena/SQuiz/common/repository/amo"
|
||||||
"gitea.pena/SQuiz/common/repository/answer"
|
"gitea.pena/SQuiz/common/repository/answer"
|
||||||
"gitea.pena/SQuiz/common/repository/bitrix"
|
|
||||||
"gitea.pena/SQuiz/common/repository/question"
|
"gitea.pena/SQuiz/common/repository/question"
|
||||||
|
"gitea.pena/SQuiz/common/repository/bitrix"
|
||||||
"gitea.pena/SQuiz/common/repository/quiz"
|
"gitea.pena/SQuiz/common/repository/quiz"
|
||||||
"gitea.pena/SQuiz/common/repository/result"
|
"gitea.pena/SQuiz/common/repository/result"
|
||||||
"gitea.pena/SQuiz/common/repository/statistics"
|
"gitea.pena/SQuiz/common/repository/statistics"
|
||||||
"gitea.pena/SQuiz/common/repository/tg"
|
"gitea.pena/SQuiz/common/repository/tg"
|
||||||
"gitea.pena/SQuiz/common/repository/workers"
|
"gitea.pena/SQuiz/common/repository/workers"
|
||||||
"gitea.pena/SQuiz/common/repository/yclients"
|
|
||||||
_ "github.com/ClickHouse/clickhouse-go"
|
|
||||||
_ "github.com/lib/pq"
|
|
||||||
"github.com/minio/minio-go/v7"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -301,72 +300,3 @@ func NewClickHouseDAL(ctx context.Context, cred string) (*ClickHouseDAL, error)
|
|||||||
func (d *ClickHouseDAL) Close(ctx context.Context) error {
|
func (d *ClickHouseDAL) Close(ctx context.Context) error {
|
||||||
return d.conn.Close()
|
return d.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
type YclientsDal struct {
|
|
||||||
conn *sql.DB
|
|
||||||
queries *sqlcgen.Queries
|
|
||||||
YclientsRepo *yclients.YclientsRepository
|
|
||||||
QuizRepo *quiz.QuizRepository
|
|
||||||
QuestionRepo *question.QuestionRepository
|
|
||||||
AccountRepo *account.AccountRepository
|
|
||||||
AnswerRepo *answer.AnswerRepository
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewYclientsDal(ctx context.Context, cred string) (*YclientsDal, error) {
|
|
||||||
pool, err := sql.Open("postgres", cred)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
if err := pool.PingContext(timeoutCtx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
queries := sqlcgen.New(pool)
|
|
||||||
|
|
||||||
yclientsRepo := yclients.NewYclientsRepository(yclients.Deps{
|
|
||||||
Queries: queries,
|
|
||||||
Pool: pool,
|
|
||||||
})
|
|
||||||
|
|
||||||
quizRepo := quiz.NewQuizRepository(quiz.Deps{
|
|
||||||
Queries: queries,
|
|
||||||
Pool: pool,
|
|
||||||
})
|
|
||||||
|
|
||||||
questionRepo := question.NewQuestionRepository(question.Deps{
|
|
||||||
Queries: queries,
|
|
||||||
Pool: pool,
|
|
||||||
})
|
|
||||||
|
|
||||||
accountRepo := account.NewAccountRepository(account.Deps{
|
|
||||||
Queries: queries,
|
|
||||||
Pool: pool,
|
|
||||||
})
|
|
||||||
|
|
||||||
answerRepo := answer.NewAnswerRepository(answer.Deps{
|
|
||||||
Queries: queries,
|
|
||||||
Pool: pool,
|
|
||||||
})
|
|
||||||
|
|
||||||
return &YclientsDal{
|
|
||||||
conn: pool,
|
|
||||||
queries: queries,
|
|
||||||
YclientsRepo: yclientsRepo,
|
|
||||||
QuizRepo: quizRepo,
|
|
||||||
QuestionRepo: questionRepo,
|
|
||||||
AccountRepo: accountRepo,
|
|
||||||
AnswerRepo: answerRepo,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *YclientsDal) Close(ctx context.Context) error {
|
|
||||||
err := d.conn.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -557,7 +557,8 @@ SELECT
|
|||||||
a.content AS last_answer_content,
|
a.content AS last_answer_content,
|
||||||
a.result,
|
a.result,
|
||||||
a.start,
|
a.start,
|
||||||
a.session
|
a.session,
|
||||||
|
a.quiz_id
|
||||||
FROM
|
FROM
|
||||||
QuizAnswers a
|
QuizAnswers a
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
@ -583,17 +584,13 @@ SELECT
|
|||||||
q.page AS question_page,
|
q.page AS question_page,
|
||||||
lc.last_answer_content AS answer_content,
|
lc.last_answer_content AS answer_content,
|
||||||
CAST(
|
CAST(
|
||||||
COUNT(CASE WHEN a.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
|
COUNT(CASE WHEN lc.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN lc.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
|
||||||
) AS percentage
|
) AS percentage
|
||||||
FROM
|
FROM
|
||||||
question q
|
question q
|
||||||
JOIN LastContent lc ON q.id = lc.question_id
|
JOIN LastContent lc ON q.id = lc.question_id
|
||||||
JOIN answer a ON q.id = a.question_id AND a.session = lc.session
|
|
||||||
WHERE
|
WHERE
|
||||||
a.quiz_id = $1
|
lc.quiz_id = $1
|
||||||
AND a.start = FALSE
|
|
||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
q.id, q.title, lc.last_answer_content
|
q.id, q.title, lc.last_answer_content
|
||||||
HAVING
|
HAVING
|
||||||
@ -1167,7 +1164,7 @@ WITH user_data AS (
|
|||||||
)
|
)
|
||||||
SELECT u.*, COUNT(*) OVER() as total_count
|
SELECT u.*, COUNT(*) OVER() as total_count
|
||||||
FROM BitrixAccountUsers u
|
FROM BitrixAccountUsers u
|
||||||
JOIN user_data a ON u.AccountID = a.BitrixID
|
JOIN user_data a ON u.BitrixID = a.BitrixID
|
||||||
WHERE u.Deleted = false
|
WHERE u.Deleted = false
|
||||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
||||||
|
|
||||||
@ -1175,7 +1172,7 @@ ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
|||||||
WITH bitrixCompany AS (
|
WITH bitrixCompany AS (
|
||||||
SELECT BitrixID FROM BitrixAccounts WHERE BitrixAccounts.AccountID = $1 AND deleted = false
|
SELECT BitrixID FROM BitrixAccounts WHERE BitrixAccounts.AccountID = $1 AND deleted = false
|
||||||
),usersDel AS (
|
),usersDel AS (
|
||||||
UPDATE BitrixAccountUsers SET Deleted = true WHERE AccountID = (SELECT BitrixID FROM bitrixCompany)
|
UPDATE BitrixAccountUsers SET Deleted = true WHERE BitrixID = (SELECT BitrixID FROM bitrixCompany)
|
||||||
),
|
),
|
||||||
companyDel AS ( UPDATE BitrixAccounts SET Deleted = true WHERE BitrixID = (SELECT BitrixID FROM bitrixCompany)
|
companyDel AS ( UPDATE BitrixAccounts SET Deleted = true WHERE BitrixID = (SELECT BitrixID FROM bitrixCompany)
|
||||||
)
|
)
|
||||||
@ -1262,7 +1259,7 @@ SELECT np.BitrixID,
|
|||||||
np.EntityTypeId,
|
np.EntityTypeId,
|
||||||
np.createdAt
|
np.createdAt
|
||||||
FROM new_pipelines np
|
FROM new_pipelines np
|
||||||
ON CONFLICT (BitrixID, AccountID, EntityTypeId) WHERE Deleted = false DO NOTHING
|
ON CONFLICT (BitrixID, AccountID) WHERE Deleted = false DO NOTHING
|
||||||
RETURNING *
|
RETURNING *
|
||||||
)
|
)
|
||||||
SELECT np.*
|
SELECT np.*
|
||||||
@ -1287,7 +1284,7 @@ WITH user_data AS (
|
|||||||
)
|
)
|
||||||
SELECT s.*, COUNT(*) OVER() as total_count
|
SELECT s.*, COUNT(*) OVER() as total_count
|
||||||
FROM StepBitrix s JOIN user_data u ON s.AccountID = u.BitrixID
|
FROM StepBitrix s JOIN user_data u ON s.AccountID = u.BitrixID
|
||||||
WHERE s.Deleted = false AND s.PipelineID = $4 ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
WHERE s.Deleted = false ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
||||||
|
|
||||||
-- name: DeleteBitrixSteps :exec
|
-- name: DeleteBitrixSteps :exec
|
||||||
UPDATE StepBitrix SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
UPDATE StepBitrix SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
||||||
@ -1319,7 +1316,7 @@ SELECT ns.BitrixID,
|
|||||||
ns.Color,
|
ns.Color,
|
||||||
ns.CreatedAt
|
ns.CreatedAt
|
||||||
FROM new_steps ns
|
FROM new_steps ns
|
||||||
ON CONFLICT (BitrixID, AccountID, EntityID) WHERE Deleted = false DO NOTHING
|
ON CONFLICT (BitrixID, AccountID) WHERE Deleted = false DO NOTHING
|
||||||
RETURNING *
|
RETURNING *
|
||||||
)
|
)
|
||||||
SELECT ns.*
|
SELECT ns.*
|
||||||
@ -1474,7 +1471,7 @@ UPDATE quiz SET gigachat = $3 WHERE id = $1 AND accountid = $2 AND deleted = fal
|
|||||||
SELECT * from quiz_utm where quizID = $1 and deleted=false;
|
SELECT * from quiz_utm where quizID = $1 and deleted=false;
|
||||||
|
|
||||||
-- name: CreateQuizUtm :one
|
-- name: CreateQuizUtm :one
|
||||||
INSERT into quiz_utm (quizID,utm,name,category) values ($1,$2,$3,$4) RETURNING *;
|
INSERT into quiz_utm (quizID,utm) values ($1,$2) RETURNING *;
|
||||||
|
|
||||||
-- name: SoftDeleteQuizUtm :exec
|
-- name: SoftDeleteQuizUtm :exec
|
||||||
UPDATE quiz_utm set deleted = true where id = $1;
|
UPDATE quiz_utm set deleted = true where id = $1;
|
||||||
@ -1493,184 +1490,4 @@ WHERE quiz_id = $1 AND privilege_id = $2;
|
|||||||
|
|
||||||
-- name: ResetQuizPrivilegeUsageCount :exec
|
-- name: ResetQuizPrivilegeUsageCount :exec
|
||||||
UPDATE quiz_privilege_usage SET used_count = 0, updated_at = CURRENT_TIMESTAMP
|
UPDATE quiz_privilege_usage SET used_count = 0, updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE quiz_id = $1 AND privilege_id = $2;
|
WHERE quiz_id = $1 AND privilege_id = $2;
|
||||||
|
|
||||||
-- Yclients
|
|
||||||
|
|
||||||
-- name: GetCurrentYclientsCompany :one
|
|
||||||
SELECT * FROM YclientsAccounts WHERE AccountID = $1 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: GetUsersYclientsWithPagination :many
|
|
||||||
WITH user_data AS (
|
|
||||||
SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
|
||||||
)
|
|
||||||
SELECT u.*, COUNT(*) OVER() as total_count
|
|
||||||
FROM YclientsAccountUsers u
|
|
||||||
JOIN user_data a ON u.SalonID = a.SalonID
|
|
||||||
WHERE u.Deleted = false
|
|
||||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
|
||||||
|
|
||||||
-- name: GetAllYclientsAccounts :many
|
|
||||||
SELECT * from YclientsAccounts where Deleted = false;
|
|
||||||
|
|
||||||
-- -- name: GetCompanyYclientsWithPagination :many
|
|
||||||
-- WITH user_data AS (
|
|
||||||
-- SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
|
||||||
-- )
|
|
||||||
-- SELECT u.*, COUNT(*) OVER() as total_count
|
|
||||||
-- FROM YclientsCompany u
|
|
||||||
-- JOIN user_data a ON u.SalonID = a.SalonID
|
|
||||||
-- WHERE u.Deleted = false
|
|
||||||
-- ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
|
||||||
|
|
||||||
-- name: GetServicesYclientsWithPagination :many
|
|
||||||
WITH user_data AS (
|
|
||||||
SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
|
||||||
)
|
|
||||||
SELECT u.*, COUNT(*) OVER() as total_count
|
|
||||||
FROM YclientsServices u
|
|
||||||
JOIN user_data a ON u.SalonID = a.SalonID
|
|
||||||
WHERE u.Deleted = false
|
|
||||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
|
||||||
|
|
||||||
-- name: GetTimeslotsYclientsWithPagination :many
|
|
||||||
WITH user_data AS (
|
|
||||||
SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
|
||||||
)
|
|
||||||
SELECT u.*, COUNT(*) OVER() as total_count
|
|
||||||
FROM YclientsTimeSlots u
|
|
||||||
JOIN user_data a ON u.SalonID = a.SalonID
|
|
||||||
WHERE u.Deleted = false
|
|
||||||
ORDER BY u.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
|
||||||
|
|
||||||
-- name: CreateYclientsAccount :one
|
|
||||||
insert into YclientsAccounts (AccountID,SalonID,Title) values ($1,$2,$3) RETURNING *;
|
|
||||||
|
|
||||||
-- name: GetUsersByIDYclients :many
|
|
||||||
SELECT * FROM YclientsAccountUsers WHERE SalonID = $1 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: UpdateYclientsAccountUser :exec
|
|
||||||
UPDATE YclientsAccountUsers SET Name = $3, Specialization = $4, IDPosition = $5, TitlePosition= $6, Fired = $7,Status = $8,Hidden=$9
|
|
||||||
WHERE SalonID = $1 AND YclientsID = $2 AND deleted = false;
|
|
||||||
|
|
||||||
-- name: AddYclientsAccountUser :exec
|
|
||||||
INSERT INTO YclientsAccountUsers (SalonID, YclientsID, Name, Specialization, IDPosition, TitlePosition,Fired,Status,Hidden,YclientsUserID)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10);
|
|
||||||
|
|
||||||
-- name: DeleteYclientsUsers :exec
|
|
||||||
UPDATE YclientsAccountUsers SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
|
||||||
|
|
||||||
-- name: GetServicesByIDYclients :many
|
|
||||||
SELECT * FROM YclientsServices WHERE SalonID = $1 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: UpdateYclientsAccountServices :exec
|
|
||||||
UPDATE YclientsServices SET SalonServiceID = $3,Title = $4, CategoryID = $5, PriceMin = $6, PriceMax= $7, Discount = $8,Comment = $9,Active=$10,ApiID=$11,Staff=$12
|
|
||||||
WHERE SalonID = $1 AND ServiceID = $2 AND deleted = false;
|
|
||||||
|
|
||||||
-- name: AddYclientsAccountService :exec
|
|
||||||
INSERT INTO YclientsServices (SalonID, ServiceID, SalonServiceID, Title, CategoryID, PriceMin,PriceMax,Discount,Comment,Active,ApiID,Staff)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12);
|
|
||||||
|
|
||||||
-- name: DeleteYclientsServices :exec
|
|
||||||
UPDATE YclientsServices SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
|
||||||
|
|
||||||
-- name: UpdateYclientsAccountTimeslots :exec
|
|
||||||
UPDATE YclientsTimeSlots SET IsEnabled = $2,WeekdaysSettings = $3, DatesSettings = $4
|
|
||||||
WHERE SalonID = $1 AND deleted = false;
|
|
||||||
|
|
||||||
-- name: AddYclientsAccountTimeslots :one
|
|
||||||
INSERT INTO YclientsTimeSlots (SalonID, IsEnabled, WeekdaysSettings, DatesSettings)
|
|
||||||
VALUES ($1, $2, $3, $4) RETURNING *;
|
|
||||||
|
|
||||||
-- name: DeleteYclientsTimeslots :exec
|
|
||||||
UPDATE YclientsTimeSlots SET Deleted = true WHERE NOT (ID = ANY($1::bigint[]));
|
|
||||||
|
|
||||||
-- name: GetTimeslotsByIDYclients :one
|
|
||||||
SELECT * FROM YclientsTimeSlots WHERE SalonID = $1 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: SoftDeleteYclientsAccount :exec
|
|
||||||
WITH account_data AS (
|
|
||||||
UPDATE YclientsAccounts SET Deleted = true WHERE YclientsAccounts.AccountID = $1
|
|
||||||
),
|
|
||||||
account_users AS (
|
|
||||||
UPDATE YclientsAccountUsers SET Deleted = true WHERE SalonID IN (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1)
|
|
||||||
),
|
|
||||||
account_services AS (
|
|
||||||
UPDATE YclientsServices SET Deleted = true WHERE SalonID IN (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1)
|
|
||||||
),
|
|
||||||
account_timeslots AS (
|
|
||||||
UPDATE YclientsTimeSlots SET Deleted = true WHERE SalonID IN (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1)
|
|
||||||
),
|
|
||||||
account_rules AS (
|
|
||||||
UPDATE YclientsRules SET Deleted = true WHERE SalonID IN (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1)
|
|
||||||
),
|
|
||||||
account_fields AS (
|
|
||||||
UPDATE YclientsFields SET Deleted = true WHERE SalonID IN (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1)
|
|
||||||
)
|
|
||||||
SELECT 1;
|
|
||||||
|
|
||||||
-- name: GetYclientsQuizRule :one
|
|
||||||
SELECT * FROM YclientsRules WHERE QuizID = $1 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: SetYclientsQuizSettings :one
|
|
||||||
INSERT INTO YclientsRules (SalonID, QuizID, Services,FieldsRule, CustomColor,StaffID)
|
|
||||||
SELECT ya.SalonID, $1 AS QuizID, $2 AS Services, $3 AS FieldsRule, $4 AS CustomColor,$6 AS StaffID
|
|
||||||
FROM YclientsAccounts ya WHERE ya.AccountID = $5 AND ya.Deleted = false
|
|
||||||
RETURNING id;
|
|
||||||
|
|
||||||
-- name: ChangeYclientsQuizSettings :one
|
|
||||||
UPDATE YclientsRules SET Services = $1, CustomColor = $2,FieldsRule = $3,StaffID=$6
|
|
||||||
WHERE SalonID = (SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $4 AND YclientsAccounts.Deleted = false)
|
|
||||||
AND QuizID = $5 AND Deleted = false RETURNING id;
|
|
||||||
|
|
||||||
-- name: GetYclientsFieldsWithPagination :many
|
|
||||||
WITH user_data AS (
|
|
||||||
SELECT SalonID FROM YclientsAccounts WHERE YclientsAccounts.AccountID = $1 AND YclientsAccounts.Deleted = false
|
|
||||||
)
|
|
||||||
SELECT f.*, COUNT(*) OVER() as total_count
|
|
||||||
FROM YclientsFields f JOIN user_data u ON f.SalonID = u.SalonID
|
|
||||||
WHERE f.Deleted = false
|
|
||||||
ORDER BY f.ID OFFSET ($2 - 1) * $3 LIMIT $3;
|
|
||||||
|
|
||||||
-- name: UpdateYclientsAccountFields :exec
|
|
||||||
UPDATE YclientsFields
|
|
||||||
SET FieldType = $3,Code = $4,Title = $5,ShowInUI = $6, UserCanEdit = $7
|
|
||||||
WHERE SalonID = $1 AND YclientsID = $2 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: GetUserYclientsFieldsByID :many
|
|
||||||
SELECT * FROM YclientsFields WHERE SalonID = $1 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: DeleteYclientsFields :exec
|
|
||||||
UPDATE YclientsFields SET Deleted = true WHERE ID = ANY($1::bigint[]);
|
|
||||||
|
|
||||||
-- name: AddYclientsAccountField :exec
|
|
||||||
INSERT INTO YclientsFields (YclientsID, SalonID, FieldType, Code, Title, ShowInUI, UserCanEdit)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7);
|
|
||||||
|
|
||||||
-- name: UpdateYclientsFieldRules :exec
|
|
||||||
UPDATE YclientsRules SET FieldsRule = $1
|
|
||||||
WHERE SalonID = $2 AND QuizID = $3 AND Deleted = false;
|
|
||||||
|
|
||||||
-- name: GettingYclientsUsersTrueResults :many
|
|
||||||
SELECT
|
|
||||||
a.quiz_id, a.id AS answer_id, a.result,
|
|
||||||
a.question_id, a.content, a.session,
|
|
||||||
COALESCE((SELECT a2.utm FROM answer a2 WHERE a2.start = true AND a2.session = a.session LIMIT 1), '{}'::jsonb) AS utm,
|
|
||||||
r.salonid, r.fieldsrule, r.staffid, r.services,
|
|
||||||
r.customcolor, u.accountid AS quiz_accountid,
|
|
||||||
a.created_at as datetime -- добавляем время result ответа
|
|
||||||
FROM answer a
|
|
||||||
INNER JOIN quiz q ON a.quiz_id = q.id
|
|
||||||
LEFT JOIN yclientscrmstatuses s ON a.id = s.AnswerID
|
|
||||||
INNER JOIN yclientsrules r ON q.id = r.QuizID
|
|
||||||
INNER JOIN yclientsaccounts u ON q.accountid = u.accountid AND r.salonid = u.salonid
|
|
||||||
WHERE a.result = true AND s.id IS NULL AND a.deleted = false
|
|
||||||
AND r.deleted = false AND q.deleted = false
|
|
||||||
AND u.deleted = false;
|
|
||||||
|
|
||||||
-- name: GetQuestionListByQuizID :many
|
|
||||||
SELECT * from question where quiz_id=$1 and deleted = false;
|
|
||||||
|
|
||||||
-- name: SaveDealYclientsStatus :exec
|
|
||||||
INSERT INTO YclientsCRMStatuses (SalonID, RecordID, AnswerID, Status)
|
|
||||||
values ($4, $1, $2, $3);
|
|
||||||
@ -48,3 +48,109 @@
|
|||||||
-- RETURNING *
|
-- RETURNING *
|
||||||
-- )
|
-- )
|
||||||
-- SELECT * from inserted_utms;
|
-- SELECT * from inserted_utms;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- WITH QuizAnswers AS (
|
||||||
|
-- SELECT
|
||||||
|
-- session, start, result, question_id, created_at, content, quiz_id
|
||||||
|
-- FROM answer
|
||||||
|
-- WHERE answer.quiz_id = 27930 AND created_at between TO_TIMESTAMP(1757785974)::timestamp and TO_TIMESTAMP(1749155806)::timestamp
|
||||||
|
-- ), QuizQuestions AS (SELECT title, page, id from question where quiz_id = 27930), Funnel AS (
|
||||||
|
-- SELECT
|
||||||
|
-- COUNT(DISTINCT a.session) FILTER (WHERE a.start = FALSE) AS count_start_false,
|
||||||
|
-- COUNT(DISTINCT a.session) FILTER (WHERE a.start = TRUE) AS count_start_true,
|
||||||
|
-- COUNT(DISTINCT CASE WHEN a.result = FALSE AND qid_true_result IS NOT NULL THEN a.session END) AS count_f_result_with_t_question,
|
||||||
|
-- COUNT(DISTINCT a.session) FILTER (WHERE a.result = TRUE) AS count_t_result
|
||||||
|
-- FROM
|
||||||
|
-- QuizAnswers a
|
||||||
|
-- LEFT JOIN (
|
||||||
|
-- SELECT DISTINCT a.session, q.id AS qid_true_result
|
||||||
|
-- FROM QuizAnswers a
|
||||||
|
-- JOIN question q ON a.question_id = q.id
|
||||||
|
-- WHERE a.result = TRUE AND a.quiz_id = 27930
|
||||||
|
-- ) AS q ON a.session = q.session
|
||||||
|
-- ),
|
||||||
|
-- Results AS (
|
||||||
|
-- SELECT
|
||||||
|
-- COALESCE(q.title, '') AS question_title,
|
||||||
|
-- COUNT(*) AS total_answers,
|
||||||
|
-- CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS FLOAT8) AS percentage
|
||||||
|
-- FROM
|
||||||
|
-- question q
|
||||||
|
-- JOIN answer a ON q.id = a.question_id
|
||||||
|
-- WHERE
|
||||||
|
-- a.quiz_id = 27930
|
||||||
|
-- AND a.created_at >= TO_TIMESTAMP(1757785974)
|
||||||
|
-- AND a.created_at <= TO_TIMESTAMP(1749155806)
|
||||||
|
-- AND a.result = TRUE
|
||||||
|
-- AND a.start = FALSE
|
||||||
|
-- GROUP BY
|
||||||
|
-- q.title, a.quiz_id, a.result
|
||||||
|
-- HAVING
|
||||||
|
-- COUNT(*) >= 1
|
||||||
|
-- ),
|
||||||
|
-- LastContent AS (
|
||||||
|
-- SELECT
|
||||||
|
-- a.question_id,
|
||||||
|
-- a.content AS last_answer_content,
|
||||||
|
-- a.result,
|
||||||
|
-- a.start,
|
||||||
|
-- a.session,
|
||||||
|
-- a.quiz_id
|
||||||
|
-- FROM
|
||||||
|
-- QuizAnswers a
|
||||||
|
-- LEFT JOIN (
|
||||||
|
-- SELECT
|
||||||
|
-- session,
|
||||||
|
-- question_id,
|
||||||
|
-- MAX(created_at) AS last_created_at
|
||||||
|
-- FROM
|
||||||
|
-- QuizAnswers
|
||||||
|
-- WHERE
|
||||||
|
-- quiz_id = 27930
|
||||||
|
-- AND start = FALSE
|
||||||
|
-- AND created_at >= TO_TIMESTAMP(1757785974)
|
||||||
|
-- AND created_at <= TO_TIMESTAMP(1749155806)
|
||||||
|
-- GROUP BY
|
||||||
|
-- question_id, session
|
||||||
|
-- ) AS last_created_at_one_session ON a.session = last_created_at_one_session.session AND a.question_id = last_created_at_one_session.question_id AND a.created_at = last_created_at_one_session.last_created_at
|
||||||
|
-- WHERE a.start = FALSE
|
||||||
|
-- ),
|
||||||
|
-- Questions AS (
|
||||||
|
-- SELECT
|
||||||
|
-- q.title AS question_title,
|
||||||
|
-- q.page AS question_page,
|
||||||
|
-- lc.last_answer_content AS answer_content,
|
||||||
|
-- CAST(
|
||||||
|
-- COUNT(CASE WHEN lc.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN lc.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
|
||||||
|
-- ) AS percentage
|
||||||
|
-- FROM
|
||||||
|
-- question q
|
||||||
|
-- JOIN LastContent lc ON q.id = lc.question_id
|
||||||
|
-- WHERE
|
||||||
|
-- lc.quiz_id = 27930
|
||||||
|
-- GROUP BY
|
||||||
|
-- q.id, q.title, lc.last_answer_content
|
||||||
|
-- HAVING
|
||||||
|
-- COUNT(*) >= 1
|
||||||
|
-- )
|
||||||
|
-- SELECT
|
||||||
|
-- Funnel.count_start_false,
|
||||||
|
-- Funnel.count_start_true,
|
||||||
|
-- Funnel.count_f_result_with_t_question,
|
||||||
|
-- Funnel.count_t_result,
|
||||||
|
-- COALESCE(Results.question_title, '') AS results_title,
|
||||||
|
-- COALESCE(Results.percentage, 0) AS results_percentage,
|
||||||
|
-- COALESCE(Questions.question_title, '') AS questions_title,
|
||||||
|
-- COALESCE(Questions.question_page, 0) AS questions_page,
|
||||||
|
-- COALESCE(Questions.answer_content, '') AS answer_content,
|
||||||
|
-- COALESCE(Questions.percentage, 0) AS questions_percentage
|
||||||
|
-- FROM
|
||||||
|
-- Funnel
|
||||||
|
-- LEFT JOIN Results ON true
|
||||||
|
-- LEFT JOIN Questions ON Questions.percentage >= 1;
|
||||||
@ -1,2 +0,0 @@
|
|||||||
ALTER table quiz_utm add column name varchar(280) not null default '';
|
|
||||||
ALTER table quiz_utm add column category varchar(50) not null default '';
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
DROP TABLE If EXISTS YclientsTokens;
|
|
||||||
DROP TABLE If EXISTS YclientsAccounts;
|
|
||||||
DROP TABLE If EXISTS YclientsAccountUsers;
|
|
||||||
-- DROP TABLE If EXISTS YclientsCompany;
|
|
||||||
DROP TABLE If EXISTS YclientsServices;
|
|
||||||
DROP TABLE If EXISTS YclientsTimeSlots;
|
|
||||||
DROP TABLE If EXISTS YclientsRules;
|
|
||||||
DROP TABLE If EXISTS YclientsFields;
|
|
||||||
DROP TABLE If EXISTS YclientsCRMStatuses;
|
|
||||||
|
|
||||||
DROP INDEX if EXISTS idx_unique_tokens_yclients;
|
|
||||||
DROP INDEX if EXISTS idx_unique_yclients_rules;
|
|
||||||
@ -1,157 +0,0 @@
|
|||||||
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'CustomFieldsTypeYclients') THEN
|
|
||||||
CREATE TYPE CustomFieldsTypeYclients AS ENUM (
|
|
||||||
'text',
|
|
||||||
'number',
|
|
||||||
'select',
|
|
||||||
'date',
|
|
||||||
'datetime'
|
|
||||||
);
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_enum
|
|
||||||
WHERE enumlabel = 'yclients_staff_id' AND enumtypid = 'question_type'::regtype
|
|
||||||
) THEN
|
|
||||||
ALTER TYPE question_type ADD VALUE 'yclients_staff_id';
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_enum
|
|
||||||
WHERE enumlabel = 'yclients_services' AND enumtypid = 'question_type'::regtype
|
|
||||||
) THEN
|
|
||||||
ALTER TYPE question_type ADD VALUE 'yclients_services';
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_enum
|
|
||||||
WHERE enumlabel = 'yclients_comment' AND enumtypid = 'question_type'::regtype
|
|
||||||
) THEN
|
|
||||||
ALTER TYPE question_type ADD VALUE 'yclients_comment';
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsTokens (
|
|
||||||
AccountID VARCHAR(30) PRIMARY KEY,
|
|
||||||
SalonID int not null, -- ID компании
|
|
||||||
AccessToken TEXT NOT NULL DEFAULT '',
|
|
||||||
Active BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
Expiration BOOLEAN NOT NULL DEFAULT FALSE, -- флаг истек ли токен
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
create UNIQUE INDEX idx_unique_tokens_yclients ON YclientsTokens (SalonID, AccountID) WHERE Active = true and Expiration = false;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsAccounts (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
AccountID VARCHAR(30) NOT NULL DEFAULT '', -- ID аккаунта у нас
|
|
||||||
SalonID INT NOT NULL, -- ID компании
|
|
||||||
Title text NOT NULL DEFAULT '',
|
|
||||||
ShortDecription text NOT NULL DEFAULT '',
|
|
||||||
Country VARCHAR(50) NOT NULL DEFAULT '',
|
|
||||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsAccountUsers (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
SalonID INT NOT NULL, -- ID компании
|
|
||||||
YclientsID INT NOT NULL, -- ID пользователя в Yclients
|
|
||||||
Name VARCHAR(512) NOT NULL DEFAULT '',
|
|
||||||
Specialization text NOT NULL DEFAULT '',
|
|
||||||
IDPosition int not null default 0,
|
|
||||||
TitlePosition text not null default 0,
|
|
||||||
Fired BOOLEAN not null default false, -- Уволен ли сотрудник
|
|
||||||
Status BOOLEAN not null default false, -- Удален ли сотрудник
|
|
||||||
Hidden BOOLEAN not null default false, -- Скрыт ли сотрудник для онлайн-записи
|
|
||||||
YclientsUserID INT NOT NULL, -- ID пользователя в Yclients2
|
|
||||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
-- CREATE TABLE IF NOT EXISTS YclientsCompany (
|
|
||||||
-- ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
-- SalonID INT NOT NULL, -- ID компании
|
|
||||||
-- Title text NOT NULL,
|
|
||||||
-- ShortDecription text NOT NULL,
|
|
||||||
-- Active INT NOT NULL,
|
|
||||||
-- Country text NOT NULL,
|
|
||||||
-- GroupPriority INT NOT NULL,
|
|
||||||
-- Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
-- CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
-- );
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsServices (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
SalonID INT NOT NULL, -- ID компании
|
|
||||||
ServiceID INT NOT NULL,
|
|
||||||
SalonServiceID INT NOT NULL,
|
|
||||||
Title text NOT NULL,
|
|
||||||
CategoryID INT NOT NULL,
|
|
||||||
PriceMin text NOT NULL,
|
|
||||||
PriceMax text NOT NULL,
|
|
||||||
Discount text NOT NULL,
|
|
||||||
Comment text NOT NULL,
|
|
||||||
Active BOOLEAN not null default false,
|
|
||||||
ApiID text NOT NULL,
|
|
||||||
Staff JSONB NOT NULL DEFAULT '{}',
|
|
||||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsTimeSlots (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
SalonID INT NOT NULL, -- ID компании
|
|
||||||
IsEnabled BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
WeekdaysSettings JSONB NOT NULL DEFAULT '[]',
|
|
||||||
DatesSettings JSONB NOT NULL DEFAULT '{}',
|
|
||||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsRules (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
SalonID INT NOT NULL, -- ID компании
|
|
||||||
QuizID INT NOT NULL, -- ID квиза на которое вешается правило
|
|
||||||
StaffID INT NOT NULL,
|
|
||||||
Services JSONB NOT NULL DEFAULT '{}',
|
|
||||||
FieldsRule JSONB NOT NULL DEFAULT '{}',
|
|
||||||
CustomColor text NOT NULL Default '',
|
|
||||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsFields (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
YclientsID INT NOT NULL, -- Айдишник field в Yclients
|
|
||||||
SalonID INT NOT NULL, -- ID компании
|
|
||||||
FieldType CustomFieldsTypeYclients NOT NULL, -- тип поля
|
|
||||||
Code text NOT NULL,
|
|
||||||
Title text NOT NULL,
|
|
||||||
ShowInUI BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
UserCanEdit BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS YclientsCRMStatuses (
|
|
||||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
|
||||||
AnswerID BIGINT NOT NULL,
|
|
||||||
SalonID INT NOT NULL,
|
|
||||||
RecordID INT NOT NULL DEFAULT 0, -- ID созданной записи в YClients
|
|
||||||
Status TEXT NOT NULL DEFAULT '', -- запись о ошибке, либо успехе
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX idx_unique_yclients_rules ON YclientsRules (SalonID, QuizID) WHERE Deleted = false;
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS YclientsTokens (
|
|
||||||
AccountID VARCHAR(30) PRIMARY KEY,
|
|
||||||
SalonID int not null, -- ID компании
|
|
||||||
AccessToken TEXT NOT NULL DEFAULT '',
|
|
||||||
Active BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
Expiration BOOLEAN NOT NULL DEFAULT FALSE, -- флаг истек ли токен
|
|
||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
create UNIQUE INDEX idx_unique_tokens_yclients ON YclientsTokens (SalonID, AccountID) WHERE Active = true and Expiration = false;
|
|
||||||
|
|
||||||
ALTER TABLE YclientsAccounts
|
|
||||||
ADD COLUMN IF NOT EXISTS ShortDecription text NOT NULL DEFAULT '',
|
|
||||||
ADD COLUMN IF NOT EXISTS Country VARCHAR(50) NOT NULL DEFAULT '';
|
|
||||||
|
|
||||||
ALTER TABLE YclientsTimeSlots
|
|
||||||
ALTER COLUMN DatesSettings SET DEFAULT '{}'::jsonb;
|
|
||||||
|
|
||||||
UPDATE YclientsTimeSlots
|
|
||||||
SET DatesSettings = '{}'::jsonb
|
|
||||||
WHERE DatesSettings = '[]'::jsonb;
|
|
||||||
|
|
||||||
ALTER TABLE YclientsServices
|
|
||||||
ALTER COLUMN PriceMin TYPE TEXT,
|
|
||||||
ALTER COLUMN PriceMax TYPE TEXT,
|
|
||||||
ALTER COLUMN Discount TYPE TEXT;
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
DROP INDEX if EXISTS idx_unique_tokens_yclients;
|
|
||||||
DROP TABLE IF EXISTS YclientsTokens;
|
|
||||||
|
|
||||||
ALTER TABLE YclientsAccounts
|
|
||||||
DROP COLUMN IF EXISTS ShortDecription,
|
|
||||||
DROP COLUMN IF EXISTS Country;
|
|
||||||
|
|
||||||
ALTER TABLE YclientsTimeSlots
|
|
||||||
ALTER COLUMN DatesSettings SET DEFAULT '[]'::jsonb;
|
|
||||||
|
|
||||||
UPDATE YclientsTimeSlots
|
|
||||||
SET DatesSettings = '[]'::jsonb
|
|
||||||
WHERE DatesSettings = '{}'::jsonb;
|
|
||||||
|
|
||||||
ALTER TABLE YclientsServices
|
|
||||||
ALTER COLUMN PriceMin TYPE FLOAT USING NULLIF(PriceMin, '')::FLOAT,
|
|
||||||
ALTER COLUMN PriceMax TYPE FLOAT USING NULLIF(PriceMax, '')::FLOAT,
|
|
||||||
ALTER COLUMN Discount TYPE INT USING NULLIF(Discount, '')::INT;
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
DROP INDEX IF EXISTS idx_unique_pipeline_bitrix;
|
|
||||||
CREATE UNIQUE INDEX idx_unique_pipeline_bitrix ON PipelineBitrix (BitrixID, AccountID) WHERE Deleted = false;
|
|
||||||
DROP INDEX IF EXISTS idx_unique_step_bitrix;
|
|
||||||
CREATE UNIQUE INDEX idx_unique_step_bitrix ON StepBitrix (BitrixID, AccountID) WHERE Deleted = false;
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
DROP INDEX IF EXISTS idx_unique_pipeline_bitrix;
|
|
||||||
CREATE UNIQUE INDEX idx_unique_pipeline_bitrix ON PipelineBitrix (BitrixID, AccountID, EntityTypeId) WHERE Deleted = false;
|
|
||||||
DROP INDEX IF EXISTS idx_unique_step_bitrix;
|
|
||||||
CREATE UNIQUE INDEX idx_unique_step_bitrix ON StepBitrix (BitrixID, AccountID, EntityID) WHERE Deleted = false;
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.30.0
|
// sqlc v1.29.0
|
||||||
|
|
||||||
package sqlcgen
|
package sqlcgen
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Code generated by sqlc. DO NOT EDIT.
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// sqlc v1.30.0
|
// sqlc v1.29.0
|
||||||
|
|
||||||
package sqlcgen
|
package sqlcgen
|
||||||
|
|
||||||
@ -274,8 +274,6 @@ type QuizUtm struct {
|
|||||||
Utm string `db:"utm" json:"utm"`
|
Utm string `db:"utm" json:"utm"`
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||||
Name string `db:"name" json:"name"`
|
|
||||||
Category string `db:"category" json:"category"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RespondentState struct {
|
type RespondentState struct {
|
||||||
@ -400,90 +398,3 @@ type Usersamo struct {
|
|||||||
Deleted bool `db:"deleted" json:"deleted"`
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Yclientsaccount struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Title string `db:"title" json:"title"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Yclientsaccountuser struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Yclientsid int32 `db:"yclientsid" json:"yclientsid"`
|
|
||||||
Name string `db:"name" json:"name"`
|
|
||||||
Specialization string `db:"specialization" json:"specialization"`
|
|
||||||
Idposition int32 `db:"idposition" json:"idposition"`
|
|
||||||
Titleposition string `db:"titleposition" json:"titleposition"`
|
|
||||||
Fired bool `db:"fired" json:"fired"`
|
|
||||||
Status bool `db:"status" json:"status"`
|
|
||||||
Hidden bool `db:"hidden" json:"hidden"`
|
|
||||||
Yclientsuserid int32 `db:"yclientsuserid" json:"yclientsuserid"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Yclientscrmstatus struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Answerid int64 `db:"answerid" json:"answerid"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Recordid int32 `db:"recordid" json:"recordid"`
|
|
||||||
Status string `db:"status" json:"status"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Yclientsfield struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Yclientsid int32 `db:"yclientsid" json:"yclientsid"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Fieldtype interface{} `db:"fieldtype" json:"fieldtype"`
|
|
||||||
Code string `db:"code" json:"code"`
|
|
||||||
Title string `db:"title" json:"title"`
|
|
||||||
Showinui bool `db:"showinui" json:"showinui"`
|
|
||||||
Usercanedit bool `db:"usercanedit" json:"usercanedit"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Yclientsrule struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Quizid int32 `db:"quizid" json:"quizid"`
|
|
||||||
Staffid int32 `db:"staffid" json:"staffid"`
|
|
||||||
Services json.RawMessage `db:"services" json:"services"`
|
|
||||||
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
|
||||||
Customcolor string `db:"customcolor" json:"customcolor"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Yclientsservice struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Serviceid int32 `db:"serviceid" json:"serviceid"`
|
|
||||||
Salonserviceid int32 `db:"salonserviceid" json:"salonserviceid"`
|
|
||||||
Title string `db:"title" json:"title"`
|
|
||||||
Categoryid int32 `db:"categoryid" json:"categoryid"`
|
|
||||||
Pricemin float64 `db:"pricemin" json:"pricemin"`
|
|
||||||
Pricemax float64 `db:"pricemax" json:"pricemax"`
|
|
||||||
Discount int32 `db:"discount" json:"discount"`
|
|
||||||
Comment string `db:"comment" json:"comment"`
|
|
||||||
Active bool `db:"active" json:"active"`
|
|
||||||
Apiid string `db:"apiid" json:"apiid"`
|
|
||||||
Staff json.RawMessage `db:"staff" json:"staff"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Yclientstimeslot struct {
|
|
||||||
ID int64 `db:"id" json:"id"`
|
|
||||||
Salonid int32 `db:"salonid" json:"salonid"`
|
|
||||||
Isenabled bool `db:"isenabled" json:"isenabled"`
|
|
||||||
Weekdayssettings json.RawMessage `db:"weekdayssettings" json:"weekdayssettings"`
|
|
||||||
Datessettings json.RawMessage `db:"datessettings" json:"datessettings"`
|
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
|
||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,6 @@ type ListDeleteUTMIDsReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PaginationReq struct {
|
type PaginationReq struct {
|
||||||
PipelineID int32 `json:"pipeline"`
|
|
||||||
/* - указание страницы пагинации. Если страница не указана, применять 0*/
|
/* - указание страницы пагинации. Если страница не указана, применять 0*/
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
/* - указание размера страницы пагинации. По умолчанию применять 25*/
|
/* - указание размера страницы пагинации. По умолчанию применять 25*/
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"gitea.pena/PenaSide/common/privilege"
|
"gitea.pena/PenaSide/common/privilege"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -16,21 +15,18 @@ const (
|
|||||||
StatusOffLimit = "offlimit"
|
StatusOffLimit = "offlimit"
|
||||||
StatusAI = "ai"
|
StatusAI = "ai"
|
||||||
|
|
||||||
TypeVariant = "variant"
|
TypeVariant = "variant"
|
||||||
TypeImages = "images"
|
TypeImages = "images"
|
||||||
TypeVarImages = "varimg"
|
TypeVarImages = "varimg"
|
||||||
TypeFile = "file"
|
TypeFile = "file"
|
||||||
TypeText = "text"
|
TypeText = "text"
|
||||||
TypeEmoji = "emoji"
|
TypeEmoji = "emoji"
|
||||||
TypeSelect = "select"
|
TypeSelect = "select"
|
||||||
TypeDate = "date"
|
TypeDate = "date"
|
||||||
TypeNumber = "number"
|
TypeNumber = "number"
|
||||||
TypePage = "page"
|
TypePage = "page"
|
||||||
TypeRating = "rating"
|
TypeRating = "rating"
|
||||||
TypeResult = "result"
|
TypeResult = "result"
|
||||||
TypeYclientsStaffID = "yclients_staff_id"
|
|
||||||
TypeYclientsServices = "yclients_services"
|
|
||||||
TypeYclientsComment = "yclients_comment"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const QuizGigaChatPrivilegeLimitUsage = 30
|
const QuizGigaChatPrivilegeLimitUsage = 30
|
||||||
@ -162,8 +158,6 @@ type ResultContent struct {
|
|||||||
Custom map[string]string `json:"customs"`
|
Custom map[string]string `json:"customs"`
|
||||||
Start bool `json:"start"`
|
Start bool `json:"start"`
|
||||||
//IMGContent ImageContent `json:"imagecontent"`
|
//IMGContent ImageContent `json:"imagecontent"`
|
||||||
|
|
||||||
Score int32 `json:"score"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageContent struct {
|
type ImageContent struct {
|
||||||
@ -364,8 +358,6 @@ type QuizUTM struct {
|
|||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
QuizID int64 `json:"quizID"`
|
QuizID int64 `json:"quizID"`
|
||||||
UTM string `json:"utm"`
|
UTM string `json:"utm"`
|
||||||
Name string `json:"name"`
|
|
||||||
Category string `json:"category"`
|
|
||||||
Deleted bool `json:"deleted"`
|
Deleted bool `json:"deleted"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,183 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type YclientsAccount struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
AccountID string `json:"accountID"` // ID аккаунта нас
|
|
||||||
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
|
||||||
Title string `json:"title"`
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type YclientsAccountUser struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
|
||||||
YclientsID int32 `json:"yclientsID"` // ID пользователя в Yclients
|
|
||||||
Name string `json:"name"`
|
|
||||||
Specialization string `json:"specialization"`
|
|
||||||
IDPosition int32 `json:"idPosition"`
|
|
||||||
TitlePosition string `json:"titlePosition"`
|
|
||||||
Fired bool `json:"fired"` // Уволен ли сотрудник
|
|
||||||
Status bool `json:"status"` //Удален ли сотрудник
|
|
||||||
Hidden bool `json:"hidden"` // Скрыт ли сотрудник для онлайн-записи
|
|
||||||
YclientsUserID int32 `json:"yclientsUserID"` // ID пользователя в Yclients2
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserListYclientsResp struct {
|
|
||||||
Count int64 `json:"count"`
|
|
||||||
Items []YclientsAccountUser `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
//type YclientsCompany struct {
|
|
||||||
// ID int64 `json:"id"`
|
|
||||||
// SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
|
||||||
// Title string `json:"title"`
|
|
||||||
// ShortDecription string `json:"shortDecription"`
|
|
||||||
// Active int32 `json:"active"`
|
|
||||||
// Country string `json:"country"`
|
|
||||||
// GroupPriority int32 `json:"groupPriority"`
|
|
||||||
// Deleted bool `json:"deleted"`
|
|
||||||
// CreatedAt time.Time `json:"createdAt"`
|
|
||||||
//}
|
|
||||||
|
|
||||||
//type CompanyListYclientsResp struct {
|
|
||||||
// Count int64 `json:"count"`
|
|
||||||
// Items []YclientsCompany `json:"items"`
|
|
||||||
//}
|
|
||||||
|
|
||||||
type YclientsServices struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
|
||||||
ServiceID int32 `json:"serviceID"`
|
|
||||||
SalonServiceID int32 `json:"salon_service_id"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
CategoryID int32 `json:"categoryID"`
|
|
||||||
PriceMin float64 `json:"priceMin"`
|
|
||||||
PriceMax float64 `json:"priceMax"`
|
|
||||||
Discount int32 `json:"discount"`
|
|
||||||
Comment string `json:"comment"`
|
|
||||||
Active bool `json:"active"`
|
|
||||||
ApiID string `json:"apiID"`
|
|
||||||
Staff []YclientsServiceStaff `json:"staff"`
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type YclientsServiceStaff struct {
|
|
||||||
ID int `json:"id"`
|
|
||||||
SeanceLength int `json:"seance_length"`
|
|
||||||
}
|
|
||||||
type ServicesListYclientsResp struct {
|
|
||||||
Count int64 `json:"count"`
|
|
||||||
Items []YclientsServices `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Timeslots struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
|
||||||
// ниже то что используется в запросе
|
|
||||||
IsEnabled bool `json:"is_enabled"`
|
|
||||||
WeekdaysSettings []WeekdaySetting `json:"weekdays_settings"`
|
|
||||||
DatesSettings []DateSetting `json:"dates_settings"`
|
|
||||||
// выше то что используется в запросе
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WeekdaySetting struct {
|
|
||||||
Weekday int `json:"weekday"`
|
|
||||||
Timeslots []int `json:"timeslots"`
|
|
||||||
Setting GridSetting `json:"setting"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DateSetting struct {
|
|
||||||
Date string `json:"date"`
|
|
||||||
Timeslots []int `json:"timeslots"`
|
|
||||||
Setting GridSetting `json:"setting"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GridSetting struct {
|
|
||||||
GridFirstTimeslot int `json:"grid_first_timeslot"`
|
|
||||||
GridLastTimeslot int `json:"grid_last_timeslot"`
|
|
||||||
GridDisplayStep int `json:"grid_display_step"`
|
|
||||||
GridNearestTimeslotDelay int `json:"grid_nearest_timeslot_delay"`
|
|
||||||
GridBaseType string `json:"grid_base_type"`
|
|
||||||
IsGridFlexible bool `json:"is_grid_flexible"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TimeslotsListYclientsResp struct {
|
|
||||||
Count int64 `json:"count"`
|
|
||||||
Items []Timeslots `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type YclientsRule struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
SalonID int32 `json:"salon_id"` // ID "аккаунта который ГЛАВНЫЙ"
|
|
||||||
QuizID int32 `json:"quizID"` // ID квиза на которое вешается правило
|
|
||||||
StaffID int32 `json:"staffID"`
|
|
||||||
Services []ServiceYclientsRule `json:"services"`
|
|
||||||
FieldsRule YclientsFieldRule `json:"fields_rule"`
|
|
||||||
CustomColor string `json:"custom_color"`
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type YclientsFieldRule struct {
|
|
||||||
QuestionID map[uint64]int32 `json:"question_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ServiceYclientsRule struct {
|
|
||||||
ID int `json:"id"`
|
|
||||||
FirstCost int `json:"first_cost"`
|
|
||||||
Discount int `json:"discount"`
|
|
||||||
Cost float64 `json:"cost"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type YclientsCustomFieldsType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
TypeYclientsText YclientsCustomFieldsType = "text" // строка длиной до 255 символов
|
|
||||||
TypeYclientsNumber YclientsCustomFieldsType = "number" // число
|
|
||||||
TypeYclientsSelect YclientsCustomFieldsType = "select" // список
|
|
||||||
TypeYclientsDate YclientsCustomFieldsType = "date" // Дата (Y-m-d)
|
|
||||||
TypeYclientsDateTime YclientsCustomFieldsType = "datetime" // Дата и время (Y-m-d H:i:s)
|
|
||||||
)
|
|
||||||
|
|
||||||
type YclientsField struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
YclientsID int32 `json:"yclientsID"`
|
|
||||||
SalonID int32 `json:"salonID"`
|
|
||||||
FieldType YclientsCustomFieldsType `json:"field_type"`
|
|
||||||
Code string `json:"code"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
ShowINUI bool `json:"show_in_ui"`
|
|
||||||
UserCanEdit bool `json:"user_can_edit"`
|
|
||||||
Deleted bool `json:"deleted"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserListYclientsFieldsResp struct {
|
|
||||||
Count int64 `json:"count"`
|
|
||||||
Items []YclientsField `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type YclientsUsersTrueResults struct {
|
|
||||||
QuizID int64
|
|
||||||
AnswerID int64
|
|
||||||
Result bool
|
|
||||||
QuestionID int64
|
|
||||||
Content string
|
|
||||||
Session string
|
|
||||||
SalonID int32
|
|
||||||
UTMs UTMSavingMap
|
|
||||||
FieldsRule YclientsFieldRule
|
|
||||||
StaffID int32
|
|
||||||
Services []ServiceYclientsRule
|
|
||||||
CustomColor string
|
|
||||||
QuizAccountID string
|
|
||||||
Datetime time.Time // время result ответа
|
|
||||||
}
|
|
||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||||
"gitea.pena/SQuiz/common/model"
|
"gitea.pena/SQuiz/common/model"
|
||||||
"gitea.pena/SQuiz/common/pj_errors"
|
"gitea.pena/SQuiz/common/pj_errors"
|
||||||
@ -364,12 +363,11 @@ func (r *BitrixRepository) GetUserPipelinesByID(ctx context.Context, bitrixID st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// методы steps
|
// методы steps
|
||||||
func (r *BitrixRepository) GetStepsWithPagination(ctx context.Context, req *model.PaginationReq, bitrixID string, pipelineID int32) (*model.UserListBitrixStepsResp, error) {
|
func (r *BitrixRepository) GetStepsWithPagination(ctx context.Context, req *model.PaginationReq, bitrixID string) (*model.UserListBitrixStepsResp, error) {
|
||||||
rows, err := r.queries.GetBitrixStepsWithPagination(ctx, sqlcgen.GetBitrixStepsWithPaginationParams{
|
rows, err := r.queries.GetBitrixStepsWithPagination(ctx, sqlcgen.GetBitrixStepsWithPaginationParams{
|
||||||
Accountid: bitrixID,
|
Accountid: bitrixID,
|
||||||
Column2: req.Page,
|
Column2: req.Page,
|
||||||
Limit: req.Size,
|
Limit: req.Size,
|
||||||
Pipelineid: pipelineID,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -5,14 +5,13 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||||
|
"gitea.pena/SQuiz/common/model"
|
||||||
|
"github.com/lib/pq"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
|
||||||
"gitea.pena/SQuiz/common/model"
|
|
||||||
"github.com/lib/pq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
@ -560,31 +559,3 @@ func (r *QuestionRepository) CheckQuestionOwner(ctx context.Context, accountID s
|
|||||||
}
|
}
|
||||||
return accountID == id, nil
|
return accountID == id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *QuestionRepository) GetQuestionListByQuizID(ctx context.Context, quizID int64) ([]model.Question, error) {
|
|
||||||
rows, err := r.queries.GetQuestionListByQuizID(ctx, quizID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var questions []model.Question
|
|
||||||
for _, row := range rows {
|
|
||||||
questions = append(questions, model.Question{
|
|
||||||
Id: uint64(row.ID),
|
|
||||||
QuizId: uint64(row.QuizID),
|
|
||||||
Title: row.Title,
|
|
||||||
Description: row.Description.String,
|
|
||||||
Type: string(row.Questiontype.([]byte)),
|
|
||||||
Required: row.Required.Bool,
|
|
||||||
Deleted: row.Deleted.Bool,
|
|
||||||
Page: int(row.Page.Int16),
|
|
||||||
Content: row.Content.String,
|
|
||||||
Version: int(row.Version.Int16),
|
|
||||||
ParentIds: row.ParentIds,
|
|
||||||
CreatedAt: row.CreatedAt.Time,
|
|
||||||
UpdatedAt: row.UpdatedAt.Time,
|
|
||||||
Auditory: row.Auditory,
|
|
||||||
Session: row.Session,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return questions, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -768,12 +768,10 @@ func (r *QuizRepository) UpdateGigaChatQuizFlag(ctx context.Context, quizID int6
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm, name, category string) (model.QuizUTM, error) {
|
func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm string) (model.QuizUTM, error) {
|
||||||
result, err := r.queries.CreateQuizUtm(ctx, sqlcgen.CreateQuizUtmParams{
|
result, err := r.queries.CreateQuizUtm(ctx, sqlcgen.CreateQuizUtmParams{
|
||||||
Quizid: quizID,
|
Quizid: quizID,
|
||||||
Utm: utm,
|
Utm: utm,
|
||||||
Name: name,
|
|
||||||
Category: category,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.QuizUTM{}, err
|
return model.QuizUTM{}, err
|
||||||
@ -783,8 +781,6 @@ func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm, n
|
|||||||
ID: result.ID,
|
ID: result.ID,
|
||||||
QuizID: result.Quizid,
|
QuizID: result.Quizid,
|
||||||
UTM: result.Utm,
|
UTM: result.Utm,
|
||||||
Name: result.Name,
|
|
||||||
Category: result.Category,
|
|
||||||
Deleted: result.Deleted,
|
Deleted: result.Deleted,
|
||||||
CreatedAt: result.CreatedAt,
|
CreatedAt: result.CreatedAt,
|
||||||
}, nil
|
}, nil
|
||||||
@ -807,8 +803,6 @@ func (r *QuizRepository) GetAllQuizUtms(ctx context.Context, quizID int64) ([]mo
|
|||||||
ID: row.ID,
|
ID: row.ID,
|
||||||
QuizID: row.Quizid,
|
QuizID: row.Quizid,
|
||||||
UTM: row.Utm,
|
UTM: row.Utm,
|
||||||
Name: row.Name,
|
|
||||||
Category: row.Category,
|
|
||||||
Deleted: row.Deleted,
|
Deleted: row.Deleted,
|
||||||
CreatedAt: row.CreatedAt,
|
CreatedAt: row.CreatedAt,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -4,12 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||||
|
"gitea.pena/SQuiz/common/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
|
||||||
"gitea.pena/SQuiz/common/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
@ -121,11 +120,11 @@ func (r *ResultRepository) GetQuizResultsCSV(ctx context.Context, quizID uint64,
|
|||||||
mainQuery := `WITH ordered_content AS (
|
mainQuery := `WITH ordered_content AS (
|
||||||
SELECT a.id, a.question_id, a.quiz_id, a.fingerprint, a.session, a.result, a.created_at, a.new, a.deleted,a.version,
|
SELECT a.id, a.question_id, a.quiz_id, a.fingerprint, a.session, a.result, a.created_at, a.new, a.deleted,a.version,
|
||||||
COALESCE(NULLIF(a.content, ''),MAX(NULLIF(a.content, '')) OVER (
|
COALESCE(NULLIF(a.content, ''),MAX(NULLIF(a.content, '')) OVER (
|
||||||
PARTITION BY a.session, a.question_id, a.result ORDER BY a.created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) AS last_not_empty
|
PARTITION BY a.session, a.question_id ORDER BY a.created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) AS last_not_empty
|
||||||
FROM answer a
|
FROM answer a
|
||||||
WHERE a.quiz_id = $1 AND a.deleted = FALSE
|
WHERE a.quiz_id = $1 AND a.deleted = FALSE
|
||||||
)
|
)
|
||||||
SELECT DISTINCT ON (a.question_id, a.result, a.session)
|
SELECT DISTINCT ON (a.question_id, a.session)
|
||||||
a.id, COALESCE(a.last_not_empty,''), a.question_id, a.quiz_id, a.fingerprint,
|
a.id, COALESCE(a.last_not_empty,''), a.question_id, a.quiz_id, a.fingerprint,
|
||||||
a.session, a.result, a.created_at, a.new, a.deleted, a.version
|
a.session, a.result, a.created_at, a.new, a.deleted, a.version
|
||||||
FROM ordered_content a WHERE EXISTS (
|
FROM ordered_content a WHERE EXISTS (
|
||||||
@ -149,8 +148,7 @@ FROM ordered_content a WHERE EXISTS (
|
|||||||
WHERE a2.session = a.session AND a2.result = TRUE AND a2.quiz_id = a.quiz_id
|
WHERE a2.session = a.session AND a2.result = TRUE AND a2.quiz_id = a.quiz_id
|
||||||
)`
|
)`
|
||||||
|
|
||||||
mainQuery += ` ORDER BY a.session, a.result, a.question_id ASC, a.created_at DESC, a.result DESC`
|
mainQuery += ` ORDER BY a.session, a.question_id ASC, a.created_at DESC, a.result DESC`
|
||||||
fmt.Println("QQQQQ", mainQuery)
|
|
||||||
|
|
||||||
rows, err := r.pool.QueryContext(ctx, mainQuery, queryParams...)
|
rows, err := r.pool.QueryContext(ctx, mainQuery, queryParams...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,800 +0,0 @@
|
|||||||
package yclients
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
|
||||||
"gitea.pena/SQuiz/common/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
type YclientsRepository struct {
|
|
||||||
queries *sqlcgen.Queries
|
|
||||||
pool *sql.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
type Deps struct {
|
|
||||||
Queries *sqlcgen.Queries
|
|
||||||
Pool *sql.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewYclientsRepository(deps Deps) *YclientsRepository {
|
|
||||||
return &YclientsRepository{
|
|
||||||
queries: deps.Queries,
|
|
||||||
pool: deps.Pool,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// users
|
|
||||||
func (r *YclientsRepository) GetCurrentAccount(ctx context.Context, accountID string) (*model.YclientsAccount, error) {
|
|
||||||
row, err := r.queries.GetCurrentYclientsCompany(ctx, accountID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
user := model.YclientsAccount{
|
|
||||||
ID: row.ID,
|
|
||||||
AccountID: row.Accountid,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
Title: row.Title,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &user, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GetAllYclientsAccounts(ctx context.Context) ([]model.YclientsAccount, error) {
|
|
||||||
rows, err := r.queries.GetAllYclientsAccounts(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var result []model.YclientsAccount
|
|
||||||
for _, row := range rows {
|
|
||||||
result = append(result, model.YclientsAccount{
|
|
||||||
ID: row.ID,
|
|
||||||
AccountID: row.Accountid,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
Title: row.Title,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListYclientsResp, error) {
|
|
||||||
rows, err := r.queries.GetUsersYclientsWithPagination(ctx, sqlcgen.GetUsersYclientsWithPaginationParams{
|
|
||||||
Accountid: accountID,
|
|
||||||
Column2: req.Page,
|
|
||||||
Limit: req.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var users []model.YclientsAccountUser
|
|
||||||
var count int64
|
|
||||||
for _, row := range rows {
|
|
||||||
users = append(users, model.YclientsAccountUser{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
YclientsID: row.Yclientsid,
|
|
||||||
Name: row.Name,
|
|
||||||
IDPosition: row.Idposition,
|
|
||||||
TitlePosition: row.Titleposition,
|
|
||||||
Fired: row.Fired,
|
|
||||||
Status: row.Status,
|
|
||||||
Hidden: row.Hidden,
|
|
||||||
YclientsUserID: row.Yclientsuserid,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
count = row.TotalCount
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := model.UserListYclientsResp{
|
|
||||||
Count: count,
|
|
||||||
Items: users,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) CreateAccount(ctx context.Context, account model.YclientsAccount) (*model.YclientsAccount, error) {
|
|
||||||
row, err := r.queries.CreateYclientsAccount(ctx, sqlcgen.CreateYclientsAccountParams{
|
|
||||||
Accountid: account.AccountID,
|
|
||||||
Salonid: account.SalonID,
|
|
||||||
Title: account.Title,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &model.YclientsAccount{
|
|
||||||
ID: row.ID,
|
|
||||||
AccountID: row.Accountid,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
Title: row.Title,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
}, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GetUserUsersByID(ctx context.Context, salonID int32) ([]model.YclientsAccountUser, error) {
|
|
||||||
rows, err := r.queries.GetUsersByIDYclients(ctx, salonID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var users []model.YclientsAccountUser
|
|
||||||
for _, row := range rows {
|
|
||||||
users = append(users, model.YclientsAccountUser{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
YclientsID: row.Yclientsid,
|
|
||||||
Name: row.Name,
|
|
||||||
IDPosition: row.Idposition,
|
|
||||||
TitlePosition: row.Titleposition,
|
|
||||||
Fired: row.Fired,
|
|
||||||
Status: row.Status,
|
|
||||||
Hidden: row.Hidden,
|
|
||||||
YclientsUserID: row.Yclientsuserid,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return users, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) UpdateAccountUser(ctx context.Context, user model.YclientsAccountUser) error {
|
|
||||||
err := r.queries.UpdateYclientsAccountUser(ctx, sqlcgen.UpdateYclientsAccountUserParams{
|
|
||||||
Salonid: user.SalonID,
|
|
||||||
Yclientsid: user.YclientsID,
|
|
||||||
Name: user.Name,
|
|
||||||
Specialization: user.Specialization,
|
|
||||||
Idposition: user.IDPosition,
|
|
||||||
Titleposition: user.TitlePosition,
|
|
||||||
Fired: user.Fired,
|
|
||||||
Status: user.Status,
|
|
||||||
Hidden: user.Hidden,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) AddAccountUser(ctx context.Context, user model.YclientsAccountUser) error {
|
|
||||||
err := r.queries.AddYclientsAccountUser(ctx, sqlcgen.AddYclientsAccountUserParams{
|
|
||||||
Salonid: user.SalonID,
|
|
||||||
Yclientsid: user.YclientsID,
|
|
||||||
Name: user.Name,
|
|
||||||
Specialization: user.Specialization,
|
|
||||||
Idposition: user.IDPosition,
|
|
||||||
Titleposition: user.TitlePosition,
|
|
||||||
Fired: user.Fired,
|
|
||||||
Status: user.Status,
|
|
||||||
Hidden: user.Hidden,
|
|
||||||
Yclientsuserid: user.YclientsUserID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) DeleteUsers(ctx context.Context, ids []int64) error {
|
|
||||||
err := r.queries.DeleteYclientsUsers(ctx, ids)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
|
||||||
err := r.queries.SoftDeleteYclientsAccount(ctx, accountID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// company
|
|
||||||
//func (r *YclientsRepository) GettingCompanyWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.CompanyListYclientsResp, error) {
|
|
||||||
// rows, err := r.queries.GetCompanyYclientsWithPagination(ctx, sqlcgen.GetCompanyYclientsWithPaginationParams{
|
|
||||||
// Accountid: accountID,
|
|
||||||
// Column2: req.Page,
|
|
||||||
// Limit: req.Size,
|
|
||||||
// })
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// var users []model.YclientsCompany
|
|
||||||
// var count int64
|
|
||||||
// for _, row := range rows {
|
|
||||||
// users = append(users, model.YclientsCompany{
|
|
||||||
// ID: row.ID,
|
|
||||||
// SalonID: row.Salonid,
|
|
||||||
// Title: row.Title,
|
|
||||||
// ShortDecription: row.Shortdecription,
|
|
||||||
// Active: row.Active,
|
|
||||||
// Country: row.Country,
|
|
||||||
// GroupPriority: row.Grouppriority,
|
|
||||||
// Deleted: row.Deleted,
|
|
||||||
// CreatedAt: row.Createdat,
|
|
||||||
// })
|
|
||||||
// count = row.TotalCount
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// resp := model.CompanyListYclientsResp{
|
|
||||||
// Count: count,
|
|
||||||
// Items: users,
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return &resp, nil
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (r *YclientsRepository) UpdateCompany() {
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
||||||
// services
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GettingServicesWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.ServicesListYclientsResp, error) {
|
|
||||||
rows, err := r.queries.GetServicesYclientsWithPagination(ctx, sqlcgen.GetServicesYclientsWithPaginationParams{
|
|
||||||
Accountid: accountID,
|
|
||||||
Column2: req.Page,
|
|
||||||
Limit: req.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var services []model.YclientsServices
|
|
||||||
var count int64
|
|
||||||
for _, row := range rows {
|
|
||||||
var staff []model.YclientsServiceStaff
|
|
||||||
err = json.Unmarshal(row.Staff, &staff)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
services = append(services, model.YclientsServices{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
ServiceID: row.Serviceid,
|
|
||||||
SalonServiceID: row.Salonserviceid,
|
|
||||||
Title: row.Title,
|
|
||||||
CategoryID: row.Categoryid,
|
|
||||||
PriceMin: row.Pricemin,
|
|
||||||
PriceMax: row.Pricemax,
|
|
||||||
Discount: row.Discount,
|
|
||||||
Comment: row.Comment,
|
|
||||||
Active: row.Active,
|
|
||||||
ApiID: row.Apiid,
|
|
||||||
Staff: staff,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
count = row.TotalCount
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := model.ServicesListYclientsResp{
|
|
||||||
Count: count,
|
|
||||||
Items: services,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GetAccountServicesByID(ctx context.Context, salonID int32) ([]model.YclientsServices, error) {
|
|
||||||
rows, err := r.queries.GetServicesByIDYclients(ctx, salonID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var services []model.YclientsServices
|
|
||||||
for _, row := range rows {
|
|
||||||
var staff []model.YclientsServiceStaff
|
|
||||||
err = json.Unmarshal(row.Staff, &staff)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
services = append(services, model.YclientsServices{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
ServiceID: row.Serviceid,
|
|
||||||
SalonServiceID: row.Salonserviceid,
|
|
||||||
Title: row.Title,
|
|
||||||
CategoryID: row.Categoryid,
|
|
||||||
PriceMin: row.Pricemin,
|
|
||||||
PriceMax: row.Pricemax,
|
|
||||||
Discount: row.Discount,
|
|
||||||
Comment: row.Comment,
|
|
||||||
Active: row.Active,
|
|
||||||
ApiID: row.Apiid,
|
|
||||||
Staff: staff,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return services, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) UpdateAccountServices(ctx context.Context, service model.YclientsServices) error {
|
|
||||||
staff, err := json.Marshal(service.Staff)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = r.queries.UpdateYclientsAccountServices(ctx, sqlcgen.UpdateYclientsAccountServicesParams{
|
|
||||||
Salonid: service.SalonID,
|
|
||||||
Serviceid: service.ServiceID,
|
|
||||||
Salonserviceid: service.SalonServiceID,
|
|
||||||
Title: service.Title,
|
|
||||||
Categoryid: service.CategoryID,
|
|
||||||
Pricemin: service.PriceMin,
|
|
||||||
Pricemax: service.PriceMax,
|
|
||||||
Discount: service.Discount,
|
|
||||||
Comment: service.Comment,
|
|
||||||
Active: service.Active,
|
|
||||||
Apiid: service.ApiID,
|
|
||||||
Staff: staff,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) AddAccountService(ctx context.Context, service model.YclientsServices) error {
|
|
||||||
staff, err := json.Marshal(service.Staff)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.queries.AddYclientsAccountService(ctx, sqlcgen.AddYclientsAccountServiceParams{
|
|
||||||
Salonid: service.SalonID,
|
|
||||||
Serviceid: service.ServiceID,
|
|
||||||
Salonserviceid: service.SalonServiceID,
|
|
||||||
Title: service.Title,
|
|
||||||
Categoryid: service.CategoryID,
|
|
||||||
Pricemin: service.PriceMin,
|
|
||||||
Pricemax: service.PriceMax,
|
|
||||||
Discount: service.Discount,
|
|
||||||
Comment: service.Comment,
|
|
||||||
Active: service.Active,
|
|
||||||
Apiid: service.ApiID,
|
|
||||||
Staff: staff,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) DeleteServices(ctx context.Context, ids []int64) error {
|
|
||||||
err := r.queries.DeleteYclientsServices(ctx, ids)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// timeslots
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GettingTimeslotsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.TimeslotsListYclientsResp, error) {
|
|
||||||
rows, err := r.queries.GetTimeslotsYclientsWithPagination(ctx, sqlcgen.GetTimeslotsYclientsWithPaginationParams{
|
|
||||||
Accountid: accountID,
|
|
||||||
Column2: req.Page,
|
|
||||||
Limit: req.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var timeslots []model.Timeslots
|
|
||||||
var count int64
|
|
||||||
for _, row := range rows {
|
|
||||||
var weekdaysSettings []model.WeekdaySetting
|
|
||||||
err = json.Unmarshal(row.Weekdayssettings, &weekdaysSettings)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var datesSettings []model.DateSetting
|
|
||||||
err = json.Unmarshal(row.Datessettings, &datesSettings)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
timeslots = append(timeslots, model.Timeslots{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
IsEnabled: row.Isenabled,
|
|
||||||
WeekdaysSettings: weekdaysSettings,
|
|
||||||
DatesSettings: datesSettings,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
count = row.TotalCount
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := model.TimeslotsListYclientsResp{
|
|
||||||
Count: count,
|
|
||||||
Items: timeslots,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) UpdateAccountTimeslots(ctx context.Context, salonID int32, timeslots model.Timeslots) error {
|
|
||||||
weekdaysSettings, err := json.Marshal(timeslots.WeekdaysSettings)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
datesSettings, err := json.Marshal(timeslots.DatesSettings)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.queries.UpdateYclientsAccountTimeslots(ctx, sqlcgen.UpdateYclientsAccountTimeslotsParams{
|
|
||||||
Salonid: salonID,
|
|
||||||
Isenabled: timeslots.IsEnabled,
|
|
||||||
Weekdayssettings: weekdaysSettings,
|
|
||||||
Datessettings: datesSettings,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) AddAccountTimeslots(ctx context.Context, salonID int32, timeslots model.Timeslots) (int64, error) {
|
|
||||||
weekdaysSettings, err := json.Marshal(timeslots.WeekdaysSettings)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
datesSettings, err := json.Marshal(timeslots.DatesSettings)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
row, err := r.queries.AddYclientsAccountTimeslots(ctx, sqlcgen.AddYclientsAccountTimeslotsParams{
|
|
||||||
Salonid: salonID,
|
|
||||||
Isenabled: timeslots.IsEnabled,
|
|
||||||
Weekdayssettings: weekdaysSettings,
|
|
||||||
Datessettings: datesSettings,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return row.ID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) DeleteTimeslots(ctx context.Context, ids []int64) error {
|
|
||||||
err := r.queries.DeleteYclientsTimeslots(ctx, ids)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GetAccountTimeslotsByID(ctx context.Context, salonID int32) (*model.Timeslots, error) {
|
|
||||||
row, err := r.queries.GetTimeslotsByIDYclients(ctx, salonID)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var weekdaysSettings []model.WeekdaySetting
|
|
||||||
err = json.Unmarshal(row.Weekdayssettings, &weekdaysSettings)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var datesSettings []model.DateSetting
|
|
||||||
err = json.Unmarshal(row.Datessettings, &datesSettings)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &model.Timeslots{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
IsEnabled: row.Isenabled,
|
|
||||||
WeekdaysSettings: weekdaysSettings,
|
|
||||||
DatesSettings: datesSettings,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// rule
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GettingQuizRules(ctx context.Context, quizID int32) (*model.YclientsRule, error) {
|
|
||||||
row, err := r.queries.GetYclientsQuizRule(ctx, quizID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var services []model.ServiceYclientsRule
|
|
||||||
err = json.Unmarshal(row.Services, &services)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var fieldsRule model.YclientsFieldRule
|
|
||||||
err = json.Unmarshal(row.Fieldsrule, &fieldsRule)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &model.YclientsRule{
|
|
||||||
ID: row.ID,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
QuizID: row.Quizid,
|
|
||||||
Services: services,
|
|
||||||
FieldsRule: fieldsRule,
|
|
||||||
CustomColor: row.Customcolor,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
StaffID: row.Staffid,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) SetQuizSettings(ctx context.Context, rule model.YclientsRule, accountID string) error {
|
|
||||||
jsonServices, err := json.Marshal(rule.Services)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
jsonFieldsRule, err := json.Marshal(rule.FieldsRule)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = r.queries.SetYclientsQuizSettings(ctx, sqlcgen.SetYclientsQuizSettingsParams{
|
|
||||||
Quizid: rule.QuizID,
|
|
||||||
Staffid: rule.StaffID,
|
|
||||||
Services: jsonServices,
|
|
||||||
Fieldsrule: jsonFieldsRule,
|
|
||||||
Customcolor: rule.CustomColor,
|
|
||||||
Accountid: accountID,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) ChangeQuizSettings(ctx context.Context, rule model.YclientsRule, accountID string) error {
|
|
||||||
jsonServices, err := json.Marshal(rule.Services)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
jsonFieldsRule, err := json.Marshal(rule.FieldsRule)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = r.queries.ChangeYclientsQuizSettings(ctx, sqlcgen.ChangeYclientsQuizSettingsParams{
|
|
||||||
Quizid: rule.QuizID,
|
|
||||||
Staffid: rule.StaffID,
|
|
||||||
Services: jsonServices,
|
|
||||||
Fieldsrule: jsonFieldsRule,
|
|
||||||
Customcolor: rule.CustomColor,
|
|
||||||
Accountid: accountID,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) UpdateFieldRules(ctx context.Context, fieldRules model.YclientsFieldRule, salonID int32, quizID int32) error {
|
|
||||||
jsonFieldsRule, err := json.Marshal(fieldRules)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = r.queries.UpdateYclientsFieldRules(ctx, sqlcgen.UpdateYclientsFieldRulesParams{
|
|
||||||
Fieldsrule: jsonFieldsRule,
|
|
||||||
Salonid: salonID,
|
|
||||||
Quizid: quizID,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// fields
|
|
||||||
func (r *YclientsRepository) GetFieldsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListYclientsFieldsResp, error) {
|
|
||||||
rows, err := r.queries.GetYclientsFieldsWithPagination(ctx, sqlcgen.GetYclientsFieldsWithPaginationParams{
|
|
||||||
Accountid: accountID,
|
|
||||||
Column2: req.Page,
|
|
||||||
Limit: req.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
var fields []model.YclientsField
|
|
||||||
|
|
||||||
for _, row := range rows {
|
|
||||||
count = row.TotalCount
|
|
||||||
|
|
||||||
var fieldType model.YclientsCustomFieldsType
|
|
||||||
f := string(row.Fieldtype.([]byte))
|
|
||||||
fieldType = model.YclientsCustomFieldsType(f)
|
|
||||||
|
|
||||||
fields = append(fields, model.YclientsField{
|
|
||||||
ID: row.ID,
|
|
||||||
YclientsID: row.Yclientsid,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
FieldType: fieldType,
|
|
||||||
Code: row.Code,
|
|
||||||
Title: row.Title,
|
|
||||||
ShowINUI: row.Showinui,
|
|
||||||
UserCanEdit: row.Usercanedit,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := model.UserListYclientsFieldsResp{
|
|
||||||
Count: count,
|
|
||||||
Items: fields,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) AddAccountField(ctx context.Context, field model.YclientsField) error {
|
|
||||||
err := r.queries.AddYclientsAccountField(ctx, sqlcgen.AddYclientsAccountFieldParams{
|
|
||||||
Yclientsid: field.YclientsID,
|
|
||||||
Salonid: field.SalonID,
|
|
||||||
Fieldtype: field.FieldType,
|
|
||||||
Code: field.Code,
|
|
||||||
Title: field.Title,
|
|
||||||
Showinui: field.ShowINUI,
|
|
||||||
Usercanedit: field.UserCanEdit,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) UpdateAccountFields(ctx context.Context, salonID int32, field model.YclientsField) error {
|
|
||||||
err := r.queries.UpdateYclientsAccountFields(ctx, sqlcgen.UpdateYclientsAccountFieldsParams{
|
|
||||||
Salonid: salonID,
|
|
||||||
Yclientsid: field.YclientsID,
|
|
||||||
Fieldtype: field.FieldType,
|
|
||||||
Code: field.Code,
|
|
||||||
Title: field.Title,
|
|
||||||
Showinui: field.ShowINUI,
|
|
||||||
Usercanedit: field.UserCanEdit,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) GetUserFieldsByID(ctx context.Context, salonID int32) ([]model.YclientsField, error) {
|
|
||||||
rows, err := r.queries.GetUserYclientsFieldsByID(ctx, salonID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var fields []model.YclientsField
|
|
||||||
for _, row := range rows {
|
|
||||||
var fieldType model.YclientsCustomFieldsType
|
|
||||||
f := string(row.Fieldtype.([]byte))
|
|
||||||
fieldType = model.YclientsCustomFieldsType(f)
|
|
||||||
|
|
||||||
fields = append(fields, model.YclientsField{
|
|
||||||
ID: row.ID,
|
|
||||||
YclientsID: row.Yclientsid,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
FieldType: fieldType,
|
|
||||||
Code: row.Code,
|
|
||||||
Title: row.Title,
|
|
||||||
ShowINUI: row.Showinui,
|
|
||||||
UserCanEdit: row.Usercanedit,
|
|
||||||
Deleted: row.Deleted,
|
|
||||||
CreatedAt: row.Createdat,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return fields, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) DeleteFields(ctx context.Context, ids []int64) error {
|
|
||||||
err := r.queries.DeleteYclientsFields(ctx, ids)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// true results fetch
|
|
||||||
// todo нужно хорошенько проверить
|
|
||||||
func (r *YclientsRepository) GettingYclientsUsersTrueResults(ctx context.Context) ([]model.YclientsUsersTrueResults, error) {
|
|
||||||
rows, err := r.queries.GettingYclientsUsersTrueResults(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var results []model.YclientsUsersTrueResults
|
|
||||||
|
|
||||||
for _, row := range rows {
|
|
||||||
var fieldsRule model.YclientsFieldRule
|
|
||||||
err = json.Unmarshal(row.Fieldsrule, &fieldsRule)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var utms model.UTMSavingMap
|
|
||||||
err = json.Unmarshal(row.Utm.([]byte), &utms)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var services []model.ServiceYclientsRule
|
|
||||||
err = json.Unmarshal(row.Services, &services)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := model.YclientsUsersTrueResults{
|
|
||||||
QuizID: row.QuizID,
|
|
||||||
AnswerID: row.AnswerID,
|
|
||||||
Result: row.Result.Bool,
|
|
||||||
QuestionID: row.QuestionID,
|
|
||||||
Content: row.Content.String,
|
|
||||||
Session: row.Session.String,
|
|
||||||
SalonID: row.Salonid,
|
|
||||||
UTMs: utms,
|
|
||||||
FieldsRule: fieldsRule,
|
|
||||||
StaffID: row.Staffid,
|
|
||||||
Services: services,
|
|
||||||
CustomColor: row.Customcolor,
|
|
||||||
QuizAccountID: row.QuizAccountid,
|
|
||||||
Datetime: row.Datetime.Time,
|
|
||||||
}
|
|
||||||
|
|
||||||
results = append(results, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
return results, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type SaveDealYclientsDeps struct {
|
|
||||||
RecordID int32
|
|
||||||
AnswerID int64
|
|
||||||
Status string
|
|
||||||
SalonID int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *YclientsRepository) SaveDealYclientsStatus(ctx context.Context, deps SaveDealYclientsDeps) error {
|
|
||||||
err := r.queries.SaveDealYclientsStatus(ctx, sqlcgen.SaveDealYclientsStatusParams{
|
|
||||||
Recordid: deps.RecordID,
|
|
||||||
Answerid: deps.AnswerID,
|
|
||||||
Status: deps.Status,
|
|
||||||
Salonid: deps.SalonID,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@ -56,14 +56,6 @@ packages:
|
|||||||
- "./dal/schema/000026_init.down.sql"
|
- "./dal/schema/000026_init.down.sql"
|
||||||
- "./dal/schema/000027_init.up.sql"
|
- "./dal/schema/000027_init.up.sql"
|
||||||
- "./dal/schema/000027_init.down.sql"
|
- "./dal/schema/000027_init.down.sql"
|
||||||
- "./dal/schema/000028_init.up.sql"
|
|
||||||
- "./dal/schema/000028_init.down.sql"
|
|
||||||
- "./dal/schema/000029_init.up.sql"
|
|
||||||
- "./dal/schema/000029_init.down.sql"
|
|
||||||
- "./dal/schema/000030_init.up.sql"
|
|
||||||
- "./dal/schema/000030_init.down.sql"
|
|
||||||
- "./dal/schema/000031_init.up.sql"
|
|
||||||
- "./dal/schema/000031_init.down.sql"
|
|
||||||
engine: "postgresql"
|
engine: "postgresql"
|
||||||
emit_json_tags: true
|
emit_json_tags: true
|
||||||
emit_db_tags: true
|
emit_db_tags: true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user