cust_customer_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package cust
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "dashoo.cn/common_definition/comm_def"
  7. modelWorkflow "dashoo.cn/micro/app/model/workflow"
  8. "dashoo.cn/opms_libary/micro_srv"
  9. "dashoo.cn/opms_libary/plugin/dingtalk/message"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/smallnest/rpcx/share"
  12. )
  13. var testTenant = "default"
  14. func fakeCtx(parent context.Context, tenant string) context.Context {
  15. ctx := context.WithValue(parent, share.ReqMetaDataKey, map[string]string{
  16. "tenant": tenant,
  17. })
  18. return ctx
  19. }
  20. func TestAssignCustomerRequestApproval(t *testing.T) {
  21. ctx := fakeCtx(context.Background(), testTenant)
  22. srv, err := NewCustomerService(ctx)
  23. if err != nil {
  24. panic(err)
  25. }
  26. instance := modelWorkflow.PlatWorkflow{}
  27. err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 66).Struct(&instance)
  28. if err != nil {
  29. panic(err)
  30. }
  31. err = srv.AssignCustomerRequestApproval(&instance, &message.MixMessage{
  32. ProcessType: "finish",
  33. // ProcessType: "terminate",
  34. Result: "agree",
  35. // Result: "refuse",
  36. })
  37. if err != nil {
  38. panic(err)
  39. }
  40. }
  41. func TestAssignMoveToPublicApproval(t *testing.T) {
  42. ctx := fakeCtx(context.Background(), testTenant)
  43. srv, err := NewCustomerService(ctx)
  44. if err != nil {
  45. panic(err)
  46. }
  47. instance := modelWorkflow.PlatWorkflow{}
  48. err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 65).Struct(&instance)
  49. if err != nil {
  50. panic(err)
  51. }
  52. err = srv.MoveToPublicApproval(&instance, &message.MixMessage{
  53. ProcessType: "finish",
  54. // ProcessType: "terminate",
  55. Result: "agree",
  56. // Result: "refuse",
  57. })
  58. if err != nil {
  59. panic(err)
  60. }
  61. }
  62. func TestAssignTransCustomerApproval(t *testing.T) {
  63. ctx := fakeCtx(context.Background(), testTenant)
  64. srv, err := NewCustomerService(ctx)
  65. if err != nil {
  66. panic(err)
  67. }
  68. instance := modelWorkflow.PlatWorkflow{}
  69. err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 67).Struct(&instance)
  70. if err != nil {
  71. panic(err)
  72. }
  73. err = srv.TransCustomerApproval(&instance, &message.MixMessage{
  74. ProcessType: "finish",
  75. // ProcessType: "terminate",
  76. Result: "agree",
  77. // Result: "refuse",
  78. })
  79. if err != nil {
  80. panic(err)
  81. }
  82. }
  83. func TestGetUser(t *testing.T) {
  84. ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{
  85. "tenant": testTenant,
  86. share.AuthKey: "iuxauv5FSTslRo+jIJhl19cupXNs5/H9kZ2o5Aazkw5LFkV7hO4gRforyS4s1yvX",
  87. })
  88. err := GetUser(ctx, 1)
  89. fmt.Println(err)
  90. }
  91. func TestGetDictDataByType(t *testing.T) {
  92. ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{
  93. "tenant": testTenant,
  94. share.AuthKey: "CpTRPY8d4MdhDOYwLe+8giLLH/By5z9W+plGyiyITHy2WRmW08Lo84Aeaj7fbBQz",
  95. })
  96. res, err := GetDictDataByType(ctx, "cust_idy")
  97. fmt.Println(res, err)
  98. }
  99. type GetDictReq struct {
  100. DictType string `p:"dictType" v:"required#字典类型不能为空"`
  101. DefaultValue string `p:"defaultValue"`
  102. }
  103. func GetDictDataByType(ctx context.Context, typ string) (map[string]string, error) {
  104. srv := micro_srv.InitMicroSrvClient("Dict", "micro_srv.auth")
  105. defer srv.Close()
  106. resp := &comm_def.CommonMsg{}
  107. err := srv.Call(ctx, "GetDictDataByType", GetDictReq{
  108. DictType: typ,
  109. }, resp)
  110. if err != nil {
  111. return nil, fmt.Errorf("获取字典 %s %s", typ, err.Error())
  112. }
  113. fmt.Println(resp.Data)
  114. data := resp.Data.(map[string]interface{})["Values"].([]interface{})
  115. fmt.Println(data)
  116. res := map[string]string{}
  117. for _, i := range data {
  118. info := i.(map[string]interface{})
  119. res[info["DictValue"].(string)] = info["DictLabel"].(string)
  120. }
  121. return res, nil
  122. }