Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/apiserver/service/dms_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
aV1 "github.com/actiontech/dms/api/dms/service/v1"
"github.com/actiontech/dms/internal/apiserver/conf"
apiError "github.com/actiontech/dms/internal/apiserver/pkg/error"
"github.com/actiontech/dms/internal/dms/biz"
"github.com/actiontech/dms/internal/dms/pkg/constant"
pkgConst "github.com/actiontech/dms/internal/dms/pkg/constant"
"github.com/actiontech/dms/internal/dms/service"
"github.com/actiontech/dms/internal/pkg/locale"
"github.com/labstack/echo/v4/middleware"
echoSwagger "github.com/swaggo/echo-swagger"

Expand Down Expand Up @@ -3692,6 +3694,9 @@ func (ctl *DMSController) AddDataExportWorkflow(c echo.Context) error {

reply, err := ctl.DMS.AddDataExportWorkflow(c.Request().Context(), req, currentUserUid)
if nil != err {
if errors.Is(err, biz.ErrDataExportWorkflowNameDuplicate) {
return NewErrResp(c, errors.New(locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.DataExportWorkflowNameDuplicateErr)), apiError.BadRequestErr)
}
return NewErrResp(c, err, apiError.DMSServiceErr)
}
return NewOkRespWithReply(c, reply)
Expand Down
4 changes: 4 additions & 0 deletions internal/dms/biz/data_export_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package biz

import (
"context"
"errors"
"time"

pkgConst "github.com/actiontech/dms/internal/dms/pkg/constant"
dmsCommonV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
utilLog "github.com/actiontech/dms/pkg/dms-common/pkg/log"
)

var ErrDataExportWorkflowNameDuplicate = errors.New("data export workflow name duplicate")

type DataExportWorkflowStatus string

const (
Expand Down Expand Up @@ -98,6 +101,7 @@ type WorkflowStep struct {

type WorkflowRepo interface {
SaveWorkflow(ctx context.Context, dataExportWorkflow *Workflow) error
IsDataExportWorkflowNameDuplicate(ctx context.Context, projectUID, workflowName string) (bool, error)
ListDataExportWorkflows(ctx context.Context, opt *ListWorkflowsOption) ([]*Workflow, int64, error)
GetDataExportWorkflow(ctx context.Context, dataExportWorkflowUid string) (*Workflow, error)
UpdateWorkflowStatusById(ctx context.Context, dataExportWorkflowUid string, status DataExportWorkflowStatus) error
Expand Down
2 changes: 1 addition & 1 deletion internal/dms/service/data_export_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (d *DMSService) AddDataExportWorkflow(ctx context.Context, req *dmsV1.AddDa
}
uid, err := d.DataExportWorkflowUsecase.AddDataExportWorkflow(ctx, currentUserUid, args)
if err != nil {
return nil, fmt.Errorf("add data export workflow failed: %v", err)
return nil, fmt.Errorf("add data export workflow failed: %w", err)
}

return &dmsV1.AddDataExportWorkflowReply{
Expand Down
15 changes: 15 additions & 0 deletions internal/dms/storage/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ func (d *WorkflowRepo) SaveWorkflow(ctx context.Context, dataExportWorkflow *biz
return nil
}

func (d *WorkflowRepo) IsDataExportWorkflowNameDuplicate(ctx context.Context, projectUID, workflowName string) (bool, error) {
var count int64
if err := transaction(d.log, ctx, d.db, func(tx *gorm.DB) error {
if err := tx.WithContext(ctx).Model(&model.Workflow{}).
Where("project_uid = ? AND name = ?", projectUID, workflowName).
Count(&count).Error; err != nil {
return fmt.Errorf("failed to check workflow name duplicate: %v", err)
}
return nil
}); err != nil {
return false, err
}
return count > 0, nil
}

func (w *WorkflowRepo) UpdateWorkflowRecord(ctx context.Context, dataExportWorkflowRecord *biz.WorkflowRecord) error {
model := convertBizWorkflowRecord(dataExportWorkflowRecord)

Expand Down
1 change: 1 addition & 0 deletions internal/pkg/locale/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DBServiceSQLQueryRuleTemplateName = "SQL Workbench audit rule template (need to
DBServiceSyncExpand = "DB instance synchronization expansion service"
DBServiceSyncVersion = "Version (Supports DMP5.23.04.0 and above)"
DBServiceUser = "DB instance connection user"
DataExportWorkflowNameDuplicateErr = "Duplicate workflow name, please modify the workflow name and resubmit."
DataWorkflowDefault = "❓ Data Export Workflow Unknown Requests"
DataWorkflowExportFailed = "⚠️ Data Export Workflow Execute Failed"
DataWorkflowExportSuccess = "✅ Data Export Workflow Execute Succeeded"
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/locale/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DBServiceSQLQueryRuleTemplateName = "工作台操作审核规则模板(需要先
DBServiceSyncExpand = "数据源同步扩展服务"
DBServiceSyncVersion = "版本(支持DMP5.23.04.0及以上版本)"
DBServiceUser = "数据源连接用户"
DataExportWorkflowNameDuplicateErr = "工单名称重复了,请您修改工单名称后重新提交工单。"
DataWorkflowDefault = "❓数据导出工单未知请求"
DataWorkflowExportFailed = "⚠️ 数据导出失败"
DataWorkflowExportSuccess = "✅ 数据导出成功"
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/locale/message_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ var (

// Data Export Workflow
var (
DataExportWorkflowNameDuplicateErr = &i18n.Message{ID: "DataExportWorkflowNameDuplicateErr", Other: "工单名称重复了,请您修改工单名称后重新提交工单。"}
DataWorkflowDefault = &i18n.Message{ID: "DataWorkflowDefault", Other: "❓数据导出工单未知请求"}
DataWorkflowExportFailed = &i18n.Message{ID: "DataWorkflowExportFailed", Other: "⚠️ 数据导出失败"}
DataWorkflowExportSuccess = &i18n.Message{ID: "DataWorkflowExportSuccess", Other: "✅ 数据导出成功"}
Expand Down