center.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package query
  2. import (
  3. "context"
  4. "gd_adm_data/apis"
  5. "strings"
  6. "gd_adm_data/errors"
  7. )
  8. type InterfaceFunc struct {
  9. Function func(ctx context.Context, params string) (reply *apis.QueryResponse, err error)
  10. NeedSupple bool
  11. NeedFormat bool
  12. }
  13. var interfaceFuncMap = map[string]InterfaceFunc{
  14. "P01": {P01, false, false},
  15. "P02": {P02, false, false},
  16. "P03": {P03, false, false},
  17. "P04": {P04, false, false},
  18. "P05": {P05, false, false},
  19. "P06": {P06, false, false},
  20. "P07": {P07, false, false},
  21. "P08": {P08, false, false},
  22. "P09": {P09, false, false},
  23. "P10": {P10, false, false},
  24. "A01": {A01, false, false},
  25. "A02": {A02, true, true},
  26. "A03": {A03, false, true},
  27. "V01": {V01, false, false},
  28. "IS01": {IS01, false, true},
  29. "V02": {V02, false, false},
  30. "U01": {U01, false, false},
  31. "U02": {U02, false, false},
  32. "A04": {A04, true, true},
  33. "A05": {A05, false, true},
  34. "P11": {P11, false, false},
  35. "F01": {F01, false, false},
  36. }
  37. func Query(ctx context.Context, req *apis.QueryRequest, reply *apis.QueryResponse) (err error) {
  38. code := strings.ToUpper(req.Code)
  39. if v, ok := interfaceFuncMap[code]; ok {
  40. vreply, err := v.Function(ctx, req.Params)
  41. if err != nil {
  42. return err
  43. }
  44. reply.Data = vreply.Data
  45. if v.NeedSupple {
  46. u02Reply, uerr := U02(ctx, reply.Data)
  47. if uerr == nil {
  48. reply.Data = u02Reply.Data
  49. }
  50. }
  51. if v.NeedFormat {
  52. f01Reply, ferr := F01(ctx, reply.Data)
  53. if ferr == nil {
  54. reply.Data = f01Reply.Data
  55. }
  56. }
  57. return nil
  58. }
  59. return errors.InterfaceNoExistError
  60. }