cust_customer_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 TestGetDictDataByType(t *testing.T) {
  84. ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{
  85. "tenant": testTenant,
  86. share.AuthKey: "CpTRPY8d4MdhDOYwLe+8giLLH/By5z9W+plGyiyITHy2WRmW08Lo84Aeaj7fbBQz",
  87. })
  88. res, err := GetDictDataByType(ctx, "cust_idy")
  89. fmt.Println(res, err)
  90. }
  91. type GetDictReq struct {
  92. DictType string `p:"dictType" v:"required#字典类型不能为空"`
  93. DefaultValue string `p:"defaultValue"`
  94. }
  95. func GetDictDataByType(ctx context.Context, typ string) (map[string]string, error) {
  96. srv := micro_srv.InitMicroSrvClient("Dict", "micro_srv.auth")
  97. defer srv.Close()
  98. resp := &comm_def.CommonMsg{}
  99. err := srv.Call(ctx, "GetDictDataByType", GetDictReq{
  100. DictType: typ,
  101. }, resp)
  102. if err != nil {
  103. return nil, fmt.Errorf("获取字典 %s %s", typ, err.Error())
  104. }
  105. fmt.Println(resp.Data)
  106. data := resp.Data.(map[string]interface{})["Values"].([]interface{})
  107. fmt.Println(data)
  108. res := map[string]string{}
  109. for _, i := range data {
  110. info := i.(map[string]interface{})
  111. res[info["DictValue"].(string)] = info["DictLabel"].(string)
  112. }
  113. return res, nil
  114. }