added logic for update privilege gigachat count
This commit is contained in:
parent
056d15094b
commit
130304d8ae
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"gitea.pena/PenaSide/hlog"
|
"gitea.pena/PenaSide/hlog"
|
||||||
"gitea.pena/SQuiz/common/dal"
|
"gitea.pena/SQuiz/common/dal"
|
||||||
"gitea.pena/SQuiz/worker/internal/answerwc"
|
"gitea.pena/SQuiz/worker/internal/answerwc"
|
||||||
@ -18,7 +19,6 @@ import (
|
|||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var zapOptions = []zap.Option{
|
var zapOptions = []zap.Option{
|
||||||
@ -115,7 +115,7 @@ func New(ctx context.Context, cfg initialize.Config, build Build) error {
|
|||||||
|
|
||||||
checkWorker := privilegewc.NewCheckWorker(privilegewc.Deps{
|
checkWorker := privilegewc.NewCheckWorker(privilegewc.Deps{
|
||||||
PrivilegeIDsDays: []string{"quizUnlimTime", "squizHideBadge"},
|
PrivilegeIDsDays: []string{"quizUnlimTime", "squizHideBadge"},
|
||||||
PrivilegeIDsCount: []string{"quizCnt", "quizManual"},
|
PrivilegeIDsCount: []string{"quizCnt", "quizManual", "quizGigaChat"},
|
||||||
TickerInterval: time.Minute,
|
TickerInterval: time.Minute,
|
||||||
PrivilegeDAL: pgdal,
|
PrivilegeDAL: pgdal,
|
||||||
CustomerClient: clients.CustomerClient,
|
CustomerClient: clients.CustomerClient,
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"gitea.pena/SQuiz/common/dal"
|
"gitea.pena/SQuiz/common/dal"
|
||||||
"gitea.pena/SQuiz/common/model"
|
"gitea.pena/SQuiz/common/model"
|
||||||
"gitea.pena/SQuiz/worker/internal/clients/gigachat"
|
"gitea.pena/SQuiz/worker/internal/clients/gigachat"
|
||||||
|
"gitea.pena/SQuiz/worker/internal/wctools"
|
||||||
"github.com/twmb/franz-go/pkg/kgo"
|
"github.com/twmb/franz-go/pkg/kgo"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"time"
|
"time"
|
||||||
@ -55,6 +56,7 @@ type MessageGigaChat struct {
|
|||||||
QuizID int64 `json:"quiz_id"`
|
QuizID int64 `json:"quiz_id"`
|
||||||
Sex int32 `json:"sex"` // 0 - female, 1 - male, 2 - not sex
|
Sex int32 `json:"sex"` // 0 - female, 1 - male, 2 - not sex
|
||||||
Age string `json:"age"`
|
Age string `json:"age"`
|
||||||
|
AccountID string `json:"account_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdJsonQuestionData struct {
|
type UpdJsonQuestionData struct {
|
||||||
@ -146,5 +148,21 @@ func (r *GigaChatTaskScheduler) handleMessage(ctx context.Context, msg MessageGi
|
|||||||
r.logger.Error("failed to create updated question", zap.Error(err))
|
r.logger.Error("failed to create updated question", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, privileges, err := r.dal.AccountRepo.GetAccAndPrivilegeByEmail(ctx, msg.AccountID)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.Error("failed to get acc/privilege", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
privilege := wctools.HasQuizGigaChatPrivilege(privileges)
|
||||||
|
if privilege != nil {
|
||||||
|
privilege.Amount--
|
||||||
|
err = r.dal.AccountRepo.UpdatePrivilegeAmount(ctx, privilege.ID, privilege.Amount)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.Error("failed to update privilege", zap.Error(err))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,15 @@ func HasQuizCntPrivilege(privileges []model.ShortPrivilege) *model.ShortPrivileg
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasQuizGigaChatPrivilege(privileges []model.ShortPrivilege) *model.ShortPrivilege {
|
||||||
|
for _, privilege := range privileges {
|
||||||
|
if privilege.PrivilegeID == "quizGigaChat" && privilege.Amount > 0 {
|
||||||
|
return &privilege
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ToJSON(data interface{}) (string, error) {
|
func ToJSON(data interface{}) (string, error) {
|
||||||
result, err := json.Marshal(data)
|
result, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,7 +156,7 @@ func ToJSON(data interface{}) (string, error) {
|
|||||||
func CleanNullContent(answers []model.ResultAnswer) []model.ResultAnswer {
|
func CleanNullContent(answers []model.ResultAnswer) []model.ResultAnswer {
|
||||||
var results []model.ResultAnswer
|
var results []model.ResultAnswer
|
||||||
for _, answer := range answers {
|
for _, answer := range answers {
|
||||||
answer.Content = strings.ReplaceAll(strings.ReplaceAll(answer.Content, "`,`", "`<br>`"),"\n","<br>")
|
answer.Content = strings.ReplaceAll(strings.ReplaceAll(answer.Content, "`,`", "`<br>`"), "\n", "<br>")
|
||||||
if answer.Content != "" {
|
if answer.Content != "" {
|
||||||
results = append(results, answer)
|
results = append(results, answer)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user