| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package solutionmanagement
-
- import (
- "context"
- "fmt"
-
- "git.x2erp.com/qdy/go-base/ctx"
- "git.x2erp.com/qdy/go-base/logger"
- "git.x2erp.com/qdy/go-base/model/response"
- "git.x2erp.com/qdy/go-base/util"
- "git.x2erp.com/qdy/go-db/factory/database"
- "git.x2erp.com/qdy/go-svc-configure/internal/tables"
- )
-
- // GetSyncSolutionDetail 获取同步方案详情(主表+子表)
- func GetSyncSolutionDetail(solutionCode string, ctx context.Context, dbFactory *database.DBFactory, reqCtx *ctx.RequestContext) *response.QueryResult[SyncSolutionDetail] {
- logger.Debug(fmt.Sprintf("GetSyncSolutionDetail-开始获取同步方案详情: %s", solutionCode))
-
- // 参数验证
- if solutionCode == "" {
- logger.ErrorC(reqCtx, "方案代码不能为空")
- return util.CreateErrorResult[SyncSolutionDetail]("方案代码不能为空", reqCtx)
- }
-
- // 获取数据库连接
- db := dbFactory.GetDB()
-
- // 查询主表信息
- var solution tables.SyncSolutionDB
- query := `
- SELECT id, solution_code, solution_type, solution_name, description, creator, created_at, updated_at, deleted_at
- FROM sync_solution
- WHERE solution_code = ? AND deleted_at IS NULL
- `
- err := db.GetContext(ctx, &solution, query, solutionCode)
- if err != nil {
- logger.ErrorC(reqCtx, fmt.Sprintf("查询同步方案主表失败: %v", err))
- return util.CreateErrorResult[SyncSolutionDetail](fmt.Sprintf("查询同步方案主表失败: %v", err), reqCtx)
- }
-
- // 查询子表信息(SQL脚本)
- var sqlScripts []tables.SyncSolutionSQLDB
- sqlQuery := `
- SELECT id, sync_id, sync_name, solution_id, code_sql, count_sql, is_active, creator, created_at, updated_at, deleted_at
- FROM sync_solution_sql
- WHERE solution_id = ? AND deleted_at IS NULL
- ORDER BY sync_id
- `
- err = db.SelectContext(ctx, &sqlScripts, sqlQuery, solutionCode)
- if err != nil {
- logger.ErrorC(reqCtx, fmt.Sprintf("查询同步方案SQL脚本失败: %v", err))
- return util.CreateErrorResult[SyncSolutionDetail](fmt.Sprintf("查询同步方案SQL脚本失败: %v", err), reqCtx)
- }
-
- logger.Debug(fmt.Sprintf("获取到同步方案详情: %s, 包含 %d 个SQL脚本", solutionCode, len(sqlScripts)))
-
- // 构建返回结果
- detail := SyncSolutionDetail{
- Solution: solution,
- SQLScripts: sqlScripts,
- }
-
- return util.CreateSuccessResultData[SyncSolutionDetail](detail, reqCtx)
- }
|