package cust import ( "context" "fmt" "testing" "dashoo.cn/common_definition/comm_def" modelWorkflow "dashoo.cn/micro/app/model/workflow" "dashoo.cn/opms_libary/micro_srv" "dashoo.cn/opms_libary/plugin/dingtalk/message" "github.com/gogf/gf/frame/g" "github.com/smallnest/rpcx/share" ) var testTenant = "default" func fakeCtx(parent context.Context, tenant string) context.Context { ctx := context.WithValue(parent, share.ReqMetaDataKey, map[string]string{ "tenant": tenant, }) return ctx } func TestAssignCustomerRequestApproval(t *testing.T) { ctx := fakeCtx(context.Background(), testTenant) srv, err := NewCustomerService(ctx) if err != nil { panic(err) } instance := modelWorkflow.PlatWorkflow{} err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 66).Struct(&instance) if err != nil { panic(err) } err = srv.AssignCustomerRequestApproval(&instance, &message.MixMessage{ ProcessType: "finish", // ProcessType: "terminate", Result: "agree", // Result: "refuse", }) if err != nil { panic(err) } } func TestAssignMoveToPublicApproval(t *testing.T) { ctx := fakeCtx(context.Background(), testTenant) srv, err := NewCustomerService(ctx) if err != nil { panic(err) } instance := modelWorkflow.PlatWorkflow{} err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 65).Struct(&instance) if err != nil { panic(err) } err = srv.MoveToPublicApproval(&instance, &message.MixMessage{ ProcessType: "finish", // ProcessType: "terminate", Result: "agree", // Result: "refuse", }) if err != nil { panic(err) } } func TestAssignTransCustomerApproval(t *testing.T) { ctx := fakeCtx(context.Background(), testTenant) srv, err := NewCustomerService(ctx) if err != nil { panic(err) } instance := modelWorkflow.PlatWorkflow{} err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 67).Struct(&instance) if err != nil { panic(err) } err = srv.TransCustomerApproval(&instance, &message.MixMessage{ ProcessType: "finish", // ProcessType: "terminate", Result: "agree", // Result: "refuse", }) if err != nil { panic(err) } } func TestGetUser(t *testing.T) { ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{ "tenant": testTenant, share.AuthKey: "iuxauv5FSTslRo+jIJhl19cupXNs5/H9kZ2o5Aazkw5LFkV7hO4gRforyS4s1yvX", }) err := GetUser(ctx, 1) fmt.Println(err) } func TestGetDictDataByType(t *testing.T) { ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{ "tenant": testTenant, share.AuthKey: "CpTRPY8d4MdhDOYwLe+8giLLH/By5z9W+plGyiyITHy2WRmW08Lo84Aeaj7fbBQz", }) res, err := GetDictDataByType(ctx, "cust_idy") fmt.Println(res, err) } type GetDictReq struct { DictType string `p:"dictType" v:"required#字典类型不能为空"` DefaultValue string `p:"defaultValue"` } func GetDictDataByType(ctx context.Context, typ string) (map[string]string, error) { srv := micro_srv.InitMicroSrvClient("Dict", "micro_srv.auth") defer srv.Close() resp := &comm_def.CommonMsg{} err := srv.Call(ctx, "GetDictDataByType", GetDictReq{ DictType: typ, }, resp) if err != nil { return nil, fmt.Errorf("获取字典 %s %s", typ, err.Error()) } fmt.Println(resp.Data) data := resp.Data.(map[string]interface{})["Values"].([]interface{}) fmt.Println(data) res := map[string]string{} for _, i := range data { info := i.(map[string]interface{}) res[info["DictValue"].(string)] = info["DictLabel"].(string) } return res, nil }