Skip to content

Commit

Permalink
Merge pull request #2413 from actiontech/issue-1468final
Browse files Browse the repository at this point in the history
SQL文件上线:以文件聚合列表页以及单个文件页
  • Loading branch information
winfredLIN authored May 9, 2024
2 parents c5f63b9 + 16bbcf6 commit 23e32c3
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 194 deletions.
3 changes: 2 additions & 1 deletion sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
v1Router.GET("/tasks/audits/:task_id/", v1.GetTask)
v1Router.GET("/tasks/audits/:task_id/sqls", v1.GetTaskSQLs)
v2Router.GET("/tasks/audits/:task_id/sqls", v2.GetTaskSQLs)
v2Router.GET("/tasks/audits/:task_id/files", v2.GetAuditTaskFileOverview)
v2Router.GET("/tasks/audits/:task_id/files", v2.GetAuditFileList)
v2Router.GET("/tasks/audits/:task_id/files/:file_id/", v2.GetAuditFileExecStatistic)
v1Router.GET("/tasks/audits/:task_id/sql_report", v1.DownloadTaskSQLReportFile)
v1Router.GET("/tasks/audits/:task_id/sql_file", v1.DownloadTaskSQLFile)
v1Router.GET("/tasks/audits/:task_id/audit_file", v1.DownloadAuditFile)
Expand Down
28 changes: 8 additions & 20 deletions sqle/api/controller/v1/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,7 @@ func GetAuditPlans(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

userId := controller.GetUserID(c)

Expand All @@ -554,7 +551,7 @@ func GetAuditPlans(c echo.Context) error {
"filter_audit_plan_type": req.FilterAuditPlanType,
"filter_audit_plan_instance_name": req.FilterAuditPlanInstanceName,
"filter_project_id": projectUid,
"limit": req.PageSize,
"limit": limit,
"current_user_id": userId,
"current_user_is_admin": up.IsAdmin(),
"offset": offset,
Expand Down Expand Up @@ -699,15 +696,12 @@ func GetAuditPlanReports(c echo.Context) error {
return controller.JSONBaseErrorReq(c, errAuditPlanNotExist)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

data := map[string]interface{}{
"project_id": projectUid,
"audit_plan_name": apName,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}
auditPlanReports, count, err := s.GetAuditPlanReportsByReq(data)
Expand Down Expand Up @@ -1403,13 +1397,10 @@ func GetAuditPlanSQLs(c echo.Context) error {
return controller.JSONBaseErrorReq(c, errAuditPlanNotExist)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

data := map[string]interface{}{
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}

Expand Down Expand Up @@ -1487,15 +1478,12 @@ func GetAuditPlanReportSQLsV1(c echo.Context) error {
return controller.JSONBaseErrorReq(c, errAuditPlanNotExist)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

data := map[string]interface{}{
"audit_plan_report_id": c.Param("audit_plan_report_id"),
"audit_plan_id": ap.ID,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}
auditPlanReportSQLs, count, err := s.GetAuditPlanReportSQLsByReq(data)
Expand Down
7 changes: 2 additions & 5 deletions sqle/api/controller/v1/sql_audit_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,7 @@ func GetSQLAuditRecordsV1(c echo.Context) error {
return controller.JSONBaseErrorReq(c, fmt.Errorf("check project manager failed: %v", err))
}

var offset uint32
if req.PageIndex > 0 {
offset = (req.PageIndex - 1) * req.PageSize
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

data := map[string]interface{}{
"filter_project_id": projectUid,
Expand All @@ -696,7 +693,7 @@ func GetSQLAuditRecordsV1(c echo.Context) error {
"filter_create_time_to": req.FilterCreateTimeTo,
"check_user_can_access": !up.IsProjectAdmin(),
"filter_audit_record_ids": req.FilterSqlAuditRecordIDs,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}
if req.FilterSQLAuditStatus == SQLAuditRecordStatusAuditing {
Expand Down
16 changes: 8 additions & 8 deletions sqle/api/controller/v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ func saveFileFromContext(c echo.Context) ([]*model.AuditFile, error) {
return nil, err
}
auditFiles := []*model.AuditFile{
model.NewFileRecord(0, 0, fileHeader.Filename, uniqueName),
model.NewFileRecord(0, 1, fileHeader.Filename, uniqueName),
}
if strings.HasSuffix(fileHeader.Filename, ".zip") {
auditFiles[0].ExecOrder = 0
auditFilesInZip, err := getFileRecordsFromZip(multipartFile, fileHeader)
if err != nil {
return nil, err
Expand All @@ -209,14 +210,16 @@ func getFileRecordsFromZip(multipartFile multipart.File, fileHeader *multipart.F
return nil, err
}
var auditFiles []*model.AuditFile
for i, srcFile := range r.File {
var execOrder uint = 1
for _, srcFile := range r.File {
// skip empty file and folder
if srcFile == nil || srcFile.FileInfo().IsDir() {
continue
}
fullName := srcFile.FileHeader.Name // full name with relative path to zip file
if strings.HasSuffix(fullName, ".sql") {
auditFiles = append(auditFiles, model.NewFileRecord(0, uint(i+1), fullName, model.GenUniqueFileName()))
auditFiles = append(auditFiles, model.NewFileRecord(0, execOrder, fullName, model.GenUniqueFileName()))
execOrder++
}
}
return auditFiles, nil
Expand Down Expand Up @@ -449,17 +452,14 @@ func GetTaskSQLs(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)
data := map[string]interface{}{
"task_id": taskId,
"filter_exec_status": req.FilterExecStatus,
"filter_audit_status": req.FilterAuditStatus,
"filter_audit_level": req.FilterAuditLevel,
"no_duplicate": req.NoDuplicate,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}

Expand Down
14 changes: 4 additions & 10 deletions sqle/api/controller/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,7 @@ func GetGlobalWorkflowsV1(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

var offset uint32
if req.PageIndex > 0 {
offset = (req.PageIndex - 1) * req.PageSize
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

data := map[string]interface{}{
"filter_subject": req.FilterSubject,
Expand All @@ -570,7 +567,7 @@ func GetGlobalWorkflowsV1(c echo.Context) error {
"filter_task_instance_name": req.FilterTaskInstanceName,
"current_user_id": user.GetIDStr(),
"check_user_can_access": user.Name != model.DefaultAdminUser, // dms-todo: 判断是否是超级管理员
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}

Expand Down Expand Up @@ -651,10 +648,7 @@ func GetWorkflowsV1(c echo.Context) error {
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
var offset uint32
if req.PageIndex > 0 {
offset = (req.PageIndex - 1) * req.PageSize
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)
data := map[string]interface{}{
"filter_workflow_id": req.FilterWorkflowID,
"filter_subject": req.FilterSubject,
Expand All @@ -669,7 +663,7 @@ func GetWorkflowsV1(c echo.Context) error {
"filter_project_id": projectUid,
"current_user_id": user.ID,
"check_user_can_access": !up.IsAdmin(),
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}
if req.FuzzyKeyword != "" {
Expand Down
14 changes: 4 additions & 10 deletions sqle/api/controller/v2/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ func GetAuditPlans(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

userId := controller.GetUserID(c)

Expand All @@ -98,7 +95,7 @@ func GetAuditPlans(c echo.Context) error {
"current_user_id": userId,
"current_user_is_admin": up.IsAdmin(),
"filter_project_id": projectUid,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}
if !up.IsAdmin() {
Expand Down Expand Up @@ -204,15 +201,12 @@ func GetAuditPlanReportSQLs(c echo.Context) error {
return controller.JSONBaseErrorReq(c, errors.NewAuditPlanNotExistErr())
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)

data := map[string]interface{}{
"audit_plan_report_id": c.Param("audit_plan_report_id"),
"audit_plan_id": ap.ID,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}
auditPlanReportSQLs, count, err := s.GetAuditPlanReportSQLsByReq(data)
Expand Down
7 changes: 2 additions & 5 deletions sqle/api/controller/v2/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,15 @@ func GetTaskSQLs(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

var offset uint32
if req.PageIndex >= 1 {
offset = req.PageSize * (req.PageIndex - 1)
}
limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)
data := map[string]interface{}{
"task_id": taskId,
"filter_exec_status": req.FilterExecStatus,
"filter_audit_status": req.FilterAuditStatus,
"filter_audit_level": req.FilterAuditLevel,
"filter_audit_file_id": req.FilterAuditFileId,
"no_duplicate": req.NoDuplicate,
"limit": req.PageSize,
"limit": limit,
"offset": offset,
}

Expand Down
Loading

0 comments on commit 23e32c3

Please sign in to comment.