Skip to content

Commit

Permalink
feat(admin/template): 更新告警发送模板接口和相关逻辑
Browse files Browse the repository at this point in the history
-将 sendType 字段改为 sendTypes,支持多对多查询
- 优化模板查询逻辑,支持按多个发送类型筛选
- 修改模板状态更新接口,支持批量更新- 重构部分代码,提高可维护性和可读性
  • Loading branch information
aide-cloud committed Jan 3, 2025
1 parent c7205a4 commit 0bb5f5a
Show file tree
Hide file tree
Showing 9 changed files with 1,331 additions and 1,154 deletions.
9 changes: 6 additions & 3 deletions api/admin/template/send_template.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ message ListSendTemplateRequest {
expression: "this.size() <= 20"
}];
// 模板类型
AlarmSendType sendType = 3;
repeated AlarmSendType sendTypes = 3;
// 状态查询
Status status = 4;
}
Expand All @@ -114,9 +114,12 @@ message ListSendTemplateReply {
}

message UpdateStatusRequest {
repeated uint32 id = 1[(buf.validate.field).cel = {
message: "必须保证修改对象数据唯一",
repeated uint32 ids = 1[(buf.validate.field).cel = {
message: "必须保证修改的模板数据唯一",
expression: "this.unique()"
}, (buf.validate.field).cel = {
message: "至少选择一个告警模板",
expression: "this.size() > 0"
}];
Status status = 2 [(buf.validate.field).cel = {
message: "请选择状态",
Expand Down
8 changes: 4 additions & 4 deletions cmd/server/palace/internal/biz/bo/send_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type (

// QuerySendTemplateListParams 查询发送模板列表参数
QuerySendTemplateListParams struct {
Page types.Pagination
Keyword string `json:"keyword"`
Status vobj.Status `json:"status"`
SendType vobj.AlarmSendType `json:"sendType"`
Page types.Pagination
Keyword string `json:"keyword"`
Status vobj.Status `json:"status"`
SendTypes []vobj.AlarmSendType `json:"sendTypes"`
}

// UpdateSendTemplateStatusParams 更新发送模板状态
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/palace/internal/biz/send_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ import (
type (
// SendTemplateBiz 告警发送模板
SendTemplateBiz struct {
sendTemplateRepo repository.SendTemplateRepo
sysTemplateRepo repository.SendTemplateRepo
teamTemplateRepo repository.TeamSendTemplate
}
)

// NewSendTemplateBiz 创建告警发送模板
func NewSendTemplateBiz(sendTemplateRepo repository.SendTemplateRepo, teamTemplateRepo repository.TeamSendTemplate) *SendTemplateBiz {
return &SendTemplateBiz{
sendTemplateRepo: sendTemplateRepo,
sysTemplateRepo: sendTemplateRepo,
teamTemplateRepo: teamTemplateRepo,
}
}

func (b *SendTemplateBiz) getSendTemplateRepo(ctx context.Context) repository.SendTemplateRepo {
if middleware.GetSourceType(ctx).IsSystem() {
return b.sendTemplateRepo
return b.sysTemplateRepo
}
return b.teamTemplateRepo
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/server/palace/internal/data/repoimpl/send_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repoimpl

import (
"context"
"github.com/aide-family/moon/pkg/vobj"

"github.com/aide-family/moon/cmd/server/palace/internal/biz/bo"
"github.com/aide-family/moon/cmd/server/palace/internal/biz/repository"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (s *sendTemplateRepositoryImpl) UpdateStatusByIds(ctx context.Context, para
status := params.Status
ids := params.Ids
mainQuery := query.Use(s.data.GetMainDB(ctx))
_, err := mainQuery.StrategyTemplate.WithContext(ctx).Where(mainQuery.SysSendTemplate.ID.In(ids...)).UpdateSimple(mainQuery.SysSendTemplate.Status.Value(status.GetValue()))
_, err := mainQuery.SysSendTemplate.WithContext(ctx).Where(mainQuery.SysSendTemplate.ID.In(ids...)).UpdateSimple(mainQuery.SysSendTemplate.Status.Value(status.GetValue()))
return err
}

Expand Down Expand Up @@ -87,8 +88,8 @@ func (s *sendTemplateRepositoryImpl) listSendTemplateModels(ctx context.Context,
wheres = append(wheres, sendQuery.Status.Eq(params.Status.GetValue()))
}

if !params.SendType.IsUnknown() {
wheres = append(wheres, sendQuery.SendType.Eq(params.SendType.GetValue()))
if len(params.SendTypes) > 0 {
wheres = append(wheres, sendQuery.SendType.In(types.SliceTo(params.SendTypes, func(item vobj.AlarmSendType) int { return item.GetValue() })...))
}

if !types.TextIsNull(params.Keyword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repoimpl

import (
"context"
"github.com/aide-family/moon/pkg/vobj"

"github.com/aide-family/moon/cmd/server/palace/internal/biz/bo"
"github.com/aide-family/moon/cmd/server/palace/internal/biz/repository"
Expand Down Expand Up @@ -113,8 +114,8 @@ func (t *teamSendTemplateRepoImpl) listSendTemplateModels(ctx context.Context, p
wheres = append(wheres, bizQuery.SysSendTemplate.Status.Eq(params.Status.GetValue()))
}

if !params.SendType.IsUnknown() {
wheres = append(wheres, bizQuery.SysSendTemplate.SendType.Eq(params.SendType.GetValue()))
if len(params.SendTypes) > 0 {
wheres = append(wheres, bizQuery.SysSendTemplate.SendType.In(types.SliceTo(params.SendTypes, func(item vobj.AlarmSendType) int { return item.GetValue() })...))
}

if !types.TextIsNull(params.Keyword) {
Expand Down
14 changes: 7 additions & 7 deletions cmd/server/palace/internal/service/builder/send_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (s *sendTemplateModuleBuild) ToAPI(template imodel.ISendTemplate) *adminapi
Content: template.GetContent(),
SendType: api.AlarmSendType(template.GetSendType()),
Status: api.Status(template.GetStatus()),
CreatedAt: template.GetCreatedAt().Time.String(),
UpdatedAt: template.GetUpdatedAt().Time.String(),
CreatedAt: template.GetCreatedAt().String(),
UpdatedAt: template.GetUpdatedAt().String(),
Remark: template.GetRemark(),
Creator: userMap[template.GetCreatorID()],
}
Expand All @@ -113,10 +113,10 @@ func (l *listSendTemplateRequestBuilder) ToBo() *bo.QuerySendTemplateListParams
return nil
}
return &bo.QuerySendTemplateListParams{
Page: types.NewPagination(l.GetPagination()),
Keyword: l.GetKeyword(),
Status: vobj.Status(l.GetStatus()),
SendType: vobj.AlarmSendType(l.GetStatus()),
Page: types.NewPagination(l.GetPagination()),
Keyword: l.GetKeyword(),
Status: vobj.Status(l.GetStatus()),
SendTypes: types.SliceTo(l.GetSendTypes(), func(t api.AlarmSendType) vobj.AlarmSendType { return vobj.AlarmSendType(t) }),
}
}

Expand All @@ -135,7 +135,7 @@ func (u *updateSendTemplateStatusRequestBuilder) ToBo() *bo.UpdateSendTemplateSt
return nil
}
return &bo.UpdateSendTemplateStatusParams{
Ids: u.GetId(),
Ids: u.GetIds(),
Status: vobj.Status(u.GetStatus()),
}
}
Expand Down
Loading

0 comments on commit 0bb5f5a

Please sign in to comment.