Skip to content

Commit ded2164

Browse files
authored
Merge pull request #2423 from actiontech/fix-issue1532-2
Fix issue1532 2
2 parents 9337453 + b5d8f78 commit ded2164

File tree

7 files changed

+206
-0
lines changed

7 files changed

+206
-0
lines changed

sqle/api/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
235235
v1ProjectRouter.PUT("/:project_name/workflows/:workflow_name/tasks/:task_id/schedule", DeprecatedBy(apiV2))
236236
v1ProjectRouter.PATCH("/:project_name/workflows/:workflow_name/", DeprecatedBy(apiV2))
237237
v1ProjectRouter.GET("/:project_name/workflows/exports", v1.ExportWorkflowV1)
238+
v1ProjectRouter.POST("/:project_name/workflows/:workflow_id/tasks/:task_id/order_file", v1.UpdateSqlFileOrderByWorkflowV1)
238239

239240
// audit plan; 智能扫描任务
240241
v1ProjectRouter.POST("/:project_name/audit_plans", v1.CreateAuditPlan)

sqle/api/controller/v1/workflow.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,27 @@ func getTerminatingTaskIDs(workflow *model.Workflow) (taskIDs []uint) {
10231023
}
10241024
return taskIDs
10251025
}
1026+
1027+
type FileToSort struct {
1028+
FileID uint `json:"file_id" valid:"required"`
1029+
NewIndex uint `json:"new_index" valid:"required"`
1030+
}
1031+
1032+
type UpdateSqlFileOrderV1Req struct {
1033+
FilesToSort []FileToSort `json:"files_to_sort"`
1034+
}
1035+
1036+
// UpdateSqlFileOrderV1
1037+
// @Summary 修改文件上线顺序
1038+
// @Description update sql file order
1039+
// @Accept json
1040+
// @Produce json
1041+
// @Tags task
1042+
// @Id updateSqlFileOrderV1
1043+
// @Security ApiKeyAuth
1044+
// @Param instance body v1.UpdateSqlFileOrderV1Req true "instance body v1.UpdateSqlFileOrderV1Req true"
1045+
// @Success 200 {object} v1.GetSqlFileOrderMethodResV1
1046+
// @router /v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file [post]
1047+
func UpdateSqlFileOrderByWorkflowV1(c echo.Context) error {
1048+
return updateSqlFileOrderByWorkflow(c)
1049+
}

sqle/api/controller/v1/workflow_ce.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
var (
1919
errCommunityEditionDoesNotSupportFeatureExportWorkflowList = errors.New(errors.EnterpriseEditionFeatures, e.New("community edition does not support feature export workflow list"))
2020
errCommunityEditionDoesNotSupportWorkflowTemplate = errors.New(errors.EnterpriseEditionFeatures, e.New("community edition does not support workflow template"))
21+
errCommunityEditionDoesNotSupportFileOrder = errors.New(errors.EnterpriseEditionFeatures, e.New("community edition does not support file order"))
2122
)
2223

2324
func exportWorkflowV1(c echo.Context) error {
@@ -42,3 +43,7 @@ func getWorkflowTemplate(c echo.Context) error {
4243
func updateWorkflowTemplate(c echo.Context) error {
4344
return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportWorkflowTemplate)
4445
}
46+
47+
func updateSqlFileOrderByWorkflow(c echo.Context) error {
48+
return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportFileOrder)
49+
}

sqle/docs/docs.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4866,6 +4866,46 @@ var doc = `{
48664866
}
48674867
}
48684868
},
4869+
"/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file": {
4870+
"post": {
4871+
"security": [
4872+
{
4873+
"ApiKeyAuth": []
4874+
}
4875+
],
4876+
"description": "update sql file order",
4877+
"consumes": [
4878+
"application/json"
4879+
],
4880+
"produces": [
4881+
"application/json"
4882+
],
4883+
"tags": [
4884+
"task"
4885+
],
4886+
"summary": "修改文件上线顺序",
4887+
"operationId": "updateSqlFileOrderV1",
4888+
"parameters": [
4889+
{
4890+
"description": "instance body v1.UpdateSqlFileOrderV1Req true",
4891+
"name": "instance",
4892+
"in": "body",
4893+
"required": true,
4894+
"schema": {
4895+
"$ref": "#/definitions/v1.UpdateSqlFileOrderV1Req"
4896+
}
4897+
}
4898+
],
4899+
"responses": {
4900+
"200": {
4901+
"description": "OK",
4902+
"schema": {
4903+
"$ref": "#/definitions/v1.GetSqlFileOrderMethodResV1"
4904+
}
4905+
}
4906+
}
4907+
}
4908+
},
48694909
"/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/terminate": {
48704910
"post": {
48714911
"security": [
@@ -9461,6 +9501,17 @@ var doc = `{
94619501
}
94629502
}
94639503
},
9504+
"v1.FileToSort": {
9505+
"type": "object",
9506+
"properties": {
9507+
"file_id": {
9508+
"type": "integer"
9509+
},
9510+
"new_index": {
9511+
"type": "integer"
9512+
}
9513+
}
9514+
},
94649515
"v1.FullSyncAuditPlanSQLsReqV1": {
94659516
"type": "object",
94669517
"properties": {
@@ -12914,6 +12965,17 @@ var doc = `{
1291412965
}
1291512966
}
1291612967
},
12968+
"v1.UpdateSqlFileOrderV1Req": {
12969+
"type": "object",
12970+
"properties": {
12971+
"files_to_sort": {
12972+
"type": "array",
12973+
"items": {
12974+
"$ref": "#/definitions/v1.FileToSort"
12975+
}
12976+
}
12977+
}
12978+
},
1291712979
"v1.UpdateSystemVariablesReqV1": {
1291812980
"type": "object",
1291912981
"properties": {

sqle/docs/swagger.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4850,6 +4850,46 @@
48504850
}
48514851
}
48524852
},
4853+
"/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file": {
4854+
"post": {
4855+
"security": [
4856+
{
4857+
"ApiKeyAuth": []
4858+
}
4859+
],
4860+
"description": "update sql file order",
4861+
"consumes": [
4862+
"application/json"
4863+
],
4864+
"produces": [
4865+
"application/json"
4866+
],
4867+
"tags": [
4868+
"task"
4869+
],
4870+
"summary": "修改文件上线顺序",
4871+
"operationId": "updateSqlFileOrderV1",
4872+
"parameters": [
4873+
{
4874+
"description": "instance body v1.UpdateSqlFileOrderV1Req true",
4875+
"name": "instance",
4876+
"in": "body",
4877+
"required": true,
4878+
"schema": {
4879+
"$ref": "#/definitions/v1.UpdateSqlFileOrderV1Req"
4880+
}
4881+
}
4882+
],
4883+
"responses": {
4884+
"200": {
4885+
"description": "OK",
4886+
"schema": {
4887+
"$ref": "#/definitions/v1.GetSqlFileOrderMethodResV1"
4888+
}
4889+
}
4890+
}
4891+
}
4892+
},
48534893
"/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/terminate": {
48544894
"post": {
48554895
"security": [
@@ -9445,6 +9485,17 @@
94459485
}
94469486
}
94479487
},
9488+
"v1.FileToSort": {
9489+
"type": "object",
9490+
"properties": {
9491+
"file_id": {
9492+
"type": "integer"
9493+
},
9494+
"new_index": {
9495+
"type": "integer"
9496+
}
9497+
}
9498+
},
94489499
"v1.FullSyncAuditPlanSQLsReqV1": {
94499500
"type": "object",
94509501
"properties": {
@@ -12898,6 +12949,17 @@
1289812949
}
1289912950
}
1290012951
},
12952+
"v1.UpdateSqlFileOrderV1Req": {
12953+
"type": "object",
12954+
"properties": {
12955+
"files_to_sort": {
12956+
"type": "array",
12957+
"items": {
12958+
"$ref": "#/definitions/v1.FileToSort"
12959+
}
12960+
}
12961+
}
12962+
},
1290112963
"v1.UpdateSystemVariablesReqV1": {
1290212964
"type": "object",
1290312965
"properties": {

sqle/docs/swagger.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,13 @@ definitions:
800800
is_feishu_notification_enabled:
801801
type: boolean
802802
type: object
803+
v1.FileToSort:
804+
properties:
805+
file_id:
806+
type: integer
807+
new_index:
808+
type: integer
809+
type: object
803810
v1.FullSyncAuditPlanSQLsReqV1:
804811
properties:
805812
audit_plan_sql_list:
@@ -3151,6 +3158,13 @@ definitions:
31513158
type: string
31523159
type: array
31533160
type: object
3161+
v1.UpdateSqlFileOrderV1Req:
3162+
properties:
3163+
files_to_sort:
3164+
items:
3165+
$ref: '#/definitions/v1.FileToSort'
3166+
type: array
3167+
type: object
31543168
v1.UpdateSystemVariablesReqV1:
31553169
properties:
31563170
cb_operation_logs_expired_hours:
@@ -7287,6 +7301,31 @@ paths:
72877301
summary: 创建工单
72887302
tags:
72897303
- workflow
7304+
/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file:
7305+
post:
7306+
consumes:
7307+
- application/json
7308+
description: update sql file order
7309+
operationId: updateSqlFileOrderV1
7310+
parameters:
7311+
- description: instance body v1.UpdateSqlFileOrderV1Req true
7312+
in: body
7313+
name: instance
7314+
required: true
7315+
schema:
7316+
$ref: '#/definitions/v1.UpdateSqlFileOrderV1Req'
7317+
produces:
7318+
- application/json
7319+
responses:
7320+
"200":
7321+
description: OK
7322+
schema:
7323+
$ref: '#/definitions/v1.GetSqlFileOrderMethodResV1'
7324+
security:
7325+
- ApiKeyAuth: []
7326+
summary: 修改文件上线顺序
7327+
tags:
7328+
- task
72907329
/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/terminate:
72917330
post:
72927331
description: execute one task on workflow

sqle/model/task_files.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ func (s *Storage) BatchCreateFileRecords(records []*AuditFile) error {
9696
})
9797
}
9898

99+
func (s *Storage) BatchSaveFileRecords(records []*AuditFile) error {
100+
return s.Tx(func(txDB *gorm.DB) error {
101+
for _, record := range records {
102+
if err := txDB.Save(record).Error; err != nil {
103+
return err
104+
}
105+
}
106+
return nil
107+
})
108+
}
109+
99110
// 单个文件中触发XX审核等级的SQL的数量统计
100111
type FileAuditStatistic struct {
101112
ErrorCount uint `json:"error_count"`
@@ -213,6 +224,8 @@ var auditFileStatisticQueryBodyTpl = `
213224
e_sql.exec_status IS NOT NULL
214225
GROUP BY
215226
a_file.id,a_file.file_name,a_file.exec_order
227+
ORDER BY
228+
a_file.exec_order
216229
{{- end }}
217230
`
218231

0 commit comments

Comments
 (0)