fix: use unprefixed im kafka tables
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"hotgo/internal/library/imkafka"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -32,52 +33,25 @@ func (s *sSysImKafkaCommand) List(ctx context.Context, in *sysin.ImKafkaCommandL
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
mod := g.DB().Model("im_admin_commands").Safe().Ctx(ctx).
|
||||
Fields(
|
||||
"id",
|
||||
"command_id",
|
||||
"tenant_id",
|
||||
"tenant_code",
|
||||
"event_id",
|
||||
"event_type",
|
||||
"biz_type",
|
||||
"biz_id",
|
||||
"idempotency_key",
|
||||
"status",
|
||||
"reason",
|
||||
"message",
|
||||
"sent_at",
|
||||
"completed_at",
|
||||
"created_by",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
)
|
||||
if in.TenantId > 0 {
|
||||
mod = mod.Where("tenant_id", in.TenantId)
|
||||
where, args := buildImKafkaCommandWhere(in)
|
||||
if err = g.DB().Raw("SELECT COUNT(*) FROM im_admin_commands "+where, args...).Scan(&totalCount); err != nil {
|
||||
err = gerror.Wrap(err, "获取IM后台命令总数失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
if in.CommandId != "" {
|
||||
mod = mod.WhereLike("command_id", "%"+in.CommandId+"%")
|
||||
page := in.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if in.EventId != "" {
|
||||
mod = mod.WhereLike("event_id", "%"+in.EventId+"%")
|
||||
perPage := in.PerPage
|
||||
if perPage <= 0 {
|
||||
perPage = 20
|
||||
}
|
||||
if in.EventType != "" {
|
||||
mod = mod.WhereLike("event_type", "%"+in.EventType+"%")
|
||||
}
|
||||
if in.BizType != "" {
|
||||
mod = mod.Where("biz_type", in.BizType)
|
||||
}
|
||||
if in.BizId != "" {
|
||||
mod = mod.WhereLike("biz_id", "%"+in.BizId+"%")
|
||||
}
|
||||
if in.Status != "" {
|
||||
mod = mod.Where("status", in.Status)
|
||||
}
|
||||
if len(in.CreatedAt) == 2 {
|
||||
mod = mod.WhereBetween("created_at", in.CreatedAt[0], in.CreatedAt[1])
|
||||
}
|
||||
mod = mod.Page(in.Page, in.PerPage).OrderDesc("id")
|
||||
if err = mod.ScanAndCount(&list, &totalCount, false); err != nil {
|
||||
offset := (page - 1) * perPage
|
||||
query := `SELECT id,command_id,tenant_id,tenant_code,event_id,event_type,biz_type,biz_id,idempotency_key,
|
||||
status,reason,message,sent_at,completed_at,created_by,created_at,updated_at
|
||||
FROM im_admin_commands ` + where + ` ORDER BY id DESC LIMIT ? OFFSET ?`
|
||||
queryArgs := append(append([]any{}, args...), perPage, offset)
|
||||
if err = g.DB().Raw(query, queryArgs...).Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, "获取IM后台命令列表失败,请稍后重试!")
|
||||
}
|
||||
return
|
||||
@@ -87,40 +61,62 @@ func (s *sSysImKafkaCommand) View(ctx context.Context, in *sysin.ImKafkaCommandV
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mod := g.DB().Model("im_admin_commands").Safe().Ctx(ctx).
|
||||
Fields(
|
||||
"id",
|
||||
"command_id",
|
||||
"tenant_id",
|
||||
"tenant_code",
|
||||
"event_id",
|
||||
"event_type",
|
||||
"biz_type",
|
||||
"biz_id",
|
||||
"idempotency_key",
|
||||
"status",
|
||||
"reason",
|
||||
"message",
|
||||
"CAST(payload AS CHAR) payload",
|
||||
"CAST(envelope AS CHAR) envelope",
|
||||
"CAST(result AS CHAR) result",
|
||||
"sent_at",
|
||||
"completed_at",
|
||||
"created_by",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
)
|
||||
query := `SELECT id,command_id,tenant_id,tenant_code,event_id,event_type,biz_type,biz_id,idempotency_key,
|
||||
status,reason,message,CAST(payload AS CHAR) payload,CAST(envelope AS CHAR) envelope,CAST(result AS CHAR) result,
|
||||
sent_at,completed_at,created_by,created_at,updated_at FROM im_admin_commands WHERE `
|
||||
args := []any{}
|
||||
if in.Id > 0 {
|
||||
mod = mod.Where("id", in.Id)
|
||||
query += "id=?"
|
||||
args = append(args, in.Id)
|
||||
} else {
|
||||
mod = mod.Where("command_id", in.CommandId)
|
||||
query += "command_id=?"
|
||||
args = append(args, in.CommandId)
|
||||
}
|
||||
if err = mod.Scan(&res); err != nil {
|
||||
query += " LIMIT 1"
|
||||
if err = g.DB().Raw(query, args...).Scan(&res); err != nil {
|
||||
return nil, gerror.Wrap(err, "获取IM后台命令详情失败,请稍后重试!")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func buildImKafkaCommandWhere(in *sysin.ImKafkaCommandListInp) (string, []any) {
|
||||
parts := []string{"1=1"}
|
||||
args := []any{}
|
||||
if in.TenantId > 0 {
|
||||
parts = append(parts, "tenant_id=?")
|
||||
args = append(args, in.TenantId)
|
||||
}
|
||||
if in.CommandId != "" {
|
||||
parts = append(parts, "command_id LIKE ?")
|
||||
args = append(args, "%"+in.CommandId+"%")
|
||||
}
|
||||
if in.EventId != "" {
|
||||
parts = append(parts, "event_id LIKE ?")
|
||||
args = append(args, "%"+in.EventId+"%")
|
||||
}
|
||||
if in.EventType != "" {
|
||||
parts = append(parts, "event_type LIKE ?")
|
||||
args = append(args, "%"+in.EventType+"%")
|
||||
}
|
||||
if in.BizType != "" {
|
||||
parts = append(parts, "biz_type=?")
|
||||
args = append(args, in.BizType)
|
||||
}
|
||||
if in.BizId != "" {
|
||||
parts = append(parts, "biz_id LIKE ?")
|
||||
args = append(args, "%"+in.BizId+"%")
|
||||
}
|
||||
if in.Status != "" {
|
||||
parts = append(parts, "status=?")
|
||||
args = append(args, in.Status)
|
||||
}
|
||||
if len(in.CreatedAt) == 2 {
|
||||
parts = append(parts, "created_at BETWEEN ? AND ?")
|
||||
args = append(args, in.CreatedAt[0], in.CreatedAt[1])
|
||||
}
|
||||
return "WHERE " + strings.Join(parts, " AND "), args
|
||||
}
|
||||
|
||||
func (s *sSysImKafkaCommand) CacheInvalidate(ctx context.Context, in *sysin.ImKafkaCacheInvalidateInp) (res *sysin.ImKafkaEventModel, err error) {
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user