No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_sync_solution_detail.go 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package solutionmanagement
  2. import (
  3. "context"
  4. "fmt"
  5. "git.x2erp.com/qdy/go-base/ctx"
  6. "git.x2erp.com/qdy/go-base/logger"
  7. "git.x2erp.com/qdy/go-base/model/response"
  8. "git.x2erp.com/qdy/go-base/util"
  9. "git.x2erp.com/qdy/go-db/factory/database"
  10. "git.x2erp.com/qdy/go-svc-configure/internal/tables"
  11. )
  12. // GetSyncSolutionDetail 获取同步方案详情(主表+子表)
  13. func GetSyncSolutionDetail(solutionCode string, ctx context.Context, dbFactory *database.DBFactory, reqCtx *ctx.RequestContext) *response.QueryResult[SyncSolutionDetail] {
  14. logger.Debug(fmt.Sprintf("GetSyncSolutionDetail-开始获取同步方案详情: %s", solutionCode))
  15. // 参数验证
  16. if solutionCode == "" {
  17. logger.ErrorC(reqCtx, "方案代码不能为空")
  18. return util.CreateErrorResult[SyncSolutionDetail]("方案代码不能为空", reqCtx)
  19. }
  20. // 获取数据库连接
  21. db := dbFactory.GetDB()
  22. // 查询主表信息
  23. var solution tables.SyncSolutionDB
  24. query := `
  25. SELECT id, solution_code, solution_type, solution_name, description, creator, created_at, updated_at, deleted_at
  26. FROM sync_solution
  27. WHERE solution_code = ? AND deleted_at IS NULL
  28. `
  29. err := db.GetContext(ctx, &solution, query, solutionCode)
  30. if err != nil {
  31. logger.ErrorC(reqCtx, fmt.Sprintf("查询同步方案主表失败: %v", err))
  32. return util.CreateErrorResult[SyncSolutionDetail](fmt.Sprintf("查询同步方案主表失败: %v", err), reqCtx)
  33. }
  34. // 查询子表信息(SQL脚本)
  35. var sqlScripts []tables.SyncSolutionSQLDB
  36. sqlQuery := `
  37. SELECT id, sync_id, sync_name, solution_id, code_sql, count_sql, is_active, creator, created_at, updated_at, deleted_at
  38. FROM sync_solution_sql
  39. WHERE solution_id = ? AND deleted_at IS NULL
  40. ORDER BY sync_id
  41. `
  42. err = db.SelectContext(ctx, &sqlScripts, sqlQuery, solutionCode)
  43. if err != nil {
  44. logger.ErrorC(reqCtx, fmt.Sprintf("查询同步方案SQL脚本失败: %v", err))
  45. return util.CreateErrorResult[SyncSolutionDetail](fmt.Sprintf("查询同步方案SQL脚本失败: %v", err), reqCtx)
  46. }
  47. logger.Debug(fmt.Sprintf("获取到同步方案详情: %s, 包含 %d 个SQL脚本", solutionCode, len(sqlScripts)))
  48. // 构建返回结果
  49. detail := SyncSolutionDetail{
  50. Solution: solution,
  51. SQLScripts: sqlScripts,
  52. }
  53. return util.CreateSuccessResultData[SyncSolutionDetail](detail, reqCtx)
  54. }