added method GettingYclientsUsersTrueResults
This commit is contained in:
parent
5d4453a673
commit
e600a4888a
@ -1657,3 +1657,21 @@ VALUES ($1, $2, $3, $4, $5, $6, $7);
|
|||||||
-- name: UpdateYclientsFieldRules :exec
|
-- name: UpdateYclientsFieldRules :exec
|
||||||
UPDATE YclientsRules SET FieldsRule = $1
|
UPDATE YclientsRules SET FieldsRule = $1
|
||||||
WHERE SalonID = $2 AND QuizID = $3 AND Deleted = false;
|
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,
|
||||||
|
t.accesstoken, r.salonid, r.fieldsrule, r.staffid, r.services,
|
||||||
|
r.customcolor, u.accountid AS quiz_accountid
|
||||||
|
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 yclientstokens t ON q.accountid = t.AccountID AND r.salonid = t.salonid
|
||||||
|
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 AND t.active = true
|
||||||
|
AND t.expiration = false;
|
||||||
|
|||||||
@ -6,6 +6,7 @@ DROP TABLE If EXIST YclientsServices;
|
|||||||
DROP TABLE If EXIST YclientsTimeSlots;
|
DROP TABLE If EXIST YclientsTimeSlots;
|
||||||
DROP TABLE If EXIST YclientsRules;
|
DROP TABLE If EXIST YclientsRules;
|
||||||
DROP TABLE If EXIST YclientsFields;
|
DROP TABLE If EXIST YclientsFields;
|
||||||
|
DROP TABLE If EXIST YclientsCRMStatuses;
|
||||||
|
|
||||||
DROP INDEX if exist idx_unique_tokens_yclients;
|
DROP INDEX if exist idx_unique_tokens_yclients;
|
||||||
DROP INDEX if exist idx_unique_yclients_rules;
|
DROP INDEX if exist idx_unique_yclients_rules;
|
||||||
@ -145,4 +145,13 @@ CREATE TABLE IF NOT EXISTS YclientsFields (
|
|||||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
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, -- 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;
|
CREATE UNIQUE INDEX idx_unique_yclients_rules ON YclientsRules (SalonID, QuizID) WHERE Deleted = false;
|
||||||
@ -426,6 +426,15 @@ type Yclientsaccountuser struct {
|
|||||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
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 sql.NullInt32 `db:"recordid" json:"recordid"`
|
||||||
|
Status string `db:"status" json:"status"`
|
||||||
|
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||||
|
}
|
||||||
|
|
||||||
type Yclientsfield struct {
|
type Yclientsfield struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Yclientsid int32 `db:"yclientsid" json:"yclientsid"`
|
Yclientsid int32 `db:"yclientsid" json:"yclientsid"`
|
||||||
|
|||||||
@ -5147,6 +5147,80 @@ func (q *Queries) GettingBitrixUsersTrueResults(ctx context.Context) ([]GettingB
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gettingYclientsUsersTrueResults = `-- 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,
|
||||||
|
t.accesstoken, r.salonid, r.fieldsrule, r.staffid, r.services,
|
||||||
|
r.customcolor, u.accountid AS quiz_accountid
|
||||||
|
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 yclientstokens t ON q.accountid = t.AccountID AND r.salonid = t.salonid
|
||||||
|
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 AND t.active = true
|
||||||
|
AND t.expiration = false
|
||||||
|
`
|
||||||
|
|
||||||
|
type GettingYclientsUsersTrueResultsRow struct {
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
AnswerID int64 `db:"answer_id" json:"answer_id"`
|
||||||
|
Result sql.NullBool `db:"result" json:"result"`
|
||||||
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
||||||
|
Content sql.NullString `db:"content" json:"content"`
|
||||||
|
Session sql.NullString `db:"session" json:"session"`
|
||||||
|
Utm interface{} `db:"utm" json:"utm"`
|
||||||
|
Accesstoken string `db:"accesstoken" json:"accesstoken"`
|
||||||
|
Salonid int32 `db:"salonid" json:"salonid"`
|
||||||
|
Fieldsrule json.RawMessage `db:"fieldsrule" json:"fieldsrule"`
|
||||||
|
Staffid int32 `db:"staffid" json:"staffid"`
|
||||||
|
Services json.RawMessage `db:"services" json:"services"`
|
||||||
|
Customcolor string `db:"customcolor" json:"customcolor"`
|
||||||
|
QuizAccountid string `db:"quiz_accountid" json:"quiz_accountid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GettingYclientsUsersTrueResults(ctx context.Context) ([]GettingYclientsUsersTrueResultsRow, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, gettingYclientsUsersTrueResults)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GettingYclientsUsersTrueResultsRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GettingYclientsUsersTrueResultsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.QuizID,
|
||||||
|
&i.AnswerID,
|
||||||
|
&i.Result,
|
||||||
|
&i.QuestionID,
|
||||||
|
&i.Content,
|
||||||
|
&i.Session,
|
||||||
|
&i.Utm,
|
||||||
|
&i.Accesstoken,
|
||||||
|
&i.Salonid,
|
||||||
|
&i.Fieldsrule,
|
||||||
|
&i.Staffid,
|
||||||
|
&i.Services,
|
||||||
|
&i.Customcolor,
|
||||||
|
&i.QuizAccountid,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const incrementQuizPrivilegeUsage = `-- name: IncrementQuizPrivilegeUsage :exec
|
const incrementQuizPrivilegeUsage = `-- name: IncrementQuizPrivilegeUsage :exec
|
||||||
UPDATE quiz_privilege_usage SET used_count = used_count + 1, updated_at = CURRENT_TIMESTAMP
|
UPDATE quiz_privilege_usage SET used_count = used_count + 1, updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE quiz_id = $1 AND privilege_id = $2
|
WHERE quiz_id = $1 AND privilege_id = $2
|
||||||
|
|||||||
@ -176,3 +176,20 @@ type UserListYclientsFieldsResp struct {
|
|||||||
Count int64 `json:"count"`
|
Count int64 `json:"count"`
|
||||||
Items []YclientsField `json:"items"`
|
Items []YclientsField `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type YclientsUsersTrueResults struct {
|
||||||
|
QuizID int64
|
||||||
|
AnswerID int64
|
||||||
|
Result bool
|
||||||
|
QuestionID int64
|
||||||
|
Content string
|
||||||
|
Session string
|
||||||
|
AccessToken string
|
||||||
|
SalonID int32
|
||||||
|
UTMs UTMSavingMap
|
||||||
|
FieldsRule YclientsFieldRule
|
||||||
|
StaffID int32
|
||||||
|
Services ServiceYclientsRule
|
||||||
|
CustomColor string
|
||||||
|
QuizAccountID string
|
||||||
|
}
|
||||||
|
|||||||
@ -810,3 +810,55 @@ func (r *YclientsRepository) DeleteFields(ctx context.Context, ids []int64) erro
|
|||||||
}
|
}
|
||||||
return nil
|
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,
|
||||||
|
AccessToken: row.Accesstoken,
|
||||||
|
SalonID: row.Salonid,
|
||||||
|
UTMs: utms,
|
||||||
|
FieldsRule: fieldsRule,
|
||||||
|
StaffID: row.Staffid,
|
||||||
|
Services: services,
|
||||||
|
CustomColor: row.Customcolor,
|
||||||
|
QuizAccountID: row.QuizAccountid,
|
||||||
|
}
|
||||||
|
|
||||||
|
results = append(results, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user