cache_erp.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package svc
  2. import (
  3. "context"
  4. "git.i2edu.net/i2/i2-bill-erp/transform"
  5. "time"
  6. )
  7. func (svc *ServiceContext) GetErpOrganSchool(ctx context.Context) ([]*transform.OrganSchool, error) {
  8. var schools = new([]*transform.OrganSchool)
  9. //res, err := svc.Transformer.GetErpSchool(ctx, &transform.Empty{})
  10. //if err != nil {
  11. // return nil, err
  12. //}
  13. //err = svc.RdCli.SetWithExpire(cacheErpSchool, res.School, 1*time.Minute)
  14. //if err != nil {
  15. // return nil, err
  16. //}
  17. if err := svc.RdCli.GetCache(cacheErpSchool, schools); err != nil {
  18. res, err := svc.Transformer.GetErpSchool(ctx, &transform.Empty{})
  19. if err != nil {
  20. return nil, err
  21. }
  22. err = svc.RdCli.SetWithExpire(cacheErpSchool, res.School, 1*time.Minute)
  23. if err != nil {
  24. return nil, err
  25. }
  26. return res.School, nil
  27. }
  28. return *schools, nil
  29. }
  30. func (svc *ServiceContext) GetErpOrganSchoolTree(ctx context.Context) ([]*transform.TreeNode, error) {
  31. var nodes = new([]*transform.TreeNode)
  32. if err := svc.RdCli.GetCache(cacheErpSchoolTree, nodes); err != nil {
  33. res, err := svc.Transformer.GetErpOrganSchTree(ctx, &transform.Empty{})
  34. if err != nil {
  35. return nil, err
  36. }
  37. err = svc.RdCli.SetWithExpire(cacheErpSchoolTree, res.Nodes, 1*time.Minute)
  38. if err != nil {
  39. return nil, err
  40. }
  41. return res.Nodes, nil
  42. }
  43. return *nodes, nil
  44. }
  45. func (svc *ServiceContext) GetErpNetworkDetailTree(ctx context.Context) ([]*transform.TreeNode, error) {
  46. var nodes = new([]*transform.TreeNode)
  47. if err := svc.RdCli.GetCache(cacheErpNetworkDetailTree, nodes); err != nil {
  48. res, err := svc.Transformer.GetErpMktNetWorkDetailTree(ctx, &transform.Empty{})
  49. if err != nil {
  50. return nil, err
  51. }
  52. err = svc.RdCli.SetWithExpire(cacheErpNetworkDetailTree, res.Nodes, 1*time.Minute)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return res.Nodes, nil
  57. }
  58. return *nodes, nil
  59. }
  60. func (svc *ServiceContext) GetErpActivity(ctx context.Context) ([]*transform.Active, error) {
  61. var actives = new([]*transform.Active)
  62. if err := svc.RdCli.GetCache(cacheErpActivity, actives); err != nil {
  63. res, err := svc.Transformer.GetErpActive(ctx, &transform.GetErpActiveReq{})
  64. if err != nil {
  65. return nil, err
  66. }
  67. err = svc.RdCli.SetWithExpire(cacheErpActivity, res.Active, 1*time.Minute)
  68. if err != nil {
  69. return nil, err
  70. }
  71. return res.Active, nil
  72. }
  73. return *actives, nil
  74. }
  75. func (svc *ServiceContext) GetErpCity(ctx context.Context) ([]*transform.TreeNode, error) {
  76. var nodes = new([]*transform.TreeNode)
  77. if err := svc.RdCli.GetCache(cacheErpCityTree, nodes); err != nil {
  78. res, err := svc.Transformer.GetErpCityTree(ctx, &transform.Empty{})
  79. if err != nil {
  80. return nil, err
  81. }
  82. err = svc.RdCli.SetWithExpire(cacheErpCityTree, res.Nodes, 1*time.Minute)
  83. if err != nil {
  84. return nil, err
  85. }
  86. return res.Nodes, nil
  87. }
  88. return *nodes, nil
  89. }