client_test.go 2.9 KB
package k3cloud

import (
	"strings"
	"testing"
)

var (
	acctID = "20211118121754866"
	// username = "Administrator"
	// password = "stxcs@888"
	username = "18559023318"
	password = "stx@123456"
	hostUrl  = "https://tianlian.test.ik3cloud.com/k3cloud"
)

func TestLogin(t *testing.T) {
	client := Client{HttpClient{HostUrl: hostUrl}}
	result, err := client.Login(acctID, username, password)
	if err != nil {
		t.Error(err)
	}
	t.Logf("%+v \n", *result)
}

func TestExecuteBillQuery(t *testing.T) {
	client, err := NewClient(hostUrl, acctID, username, password)
	if err != nil {
		t.Error(err)
		return
	}
	//参见 物料元数据
	// _ = [][2]string{{"FMATERIALID", "表主键"}, {"FDocumentStatus", "数据状态"}, {"FForbidStatus", "禁用状态"}, {"FName", "名称"}, {"FNumber", "编码"}, {"FDescription", "描述"},
	// 	{"FCreateDate", "创建日期"}, {"FModifyDate", "修改日期"}, {"FMnemonicCode", "助记码"}, {"FSpecification", "规格型号"}, {"FForbidDate", "禁用日期"},
	// 	{"FApproveDate", "审核日期"}, {"FOldNumber", "旧物料编码"}, {"FMaterialGroup", "物料分组"}, {"FPLMMaterialId", "PLM物料内码"}, {"FMaterialSRC", "物料来源"},
	// 	{"FIsSalseByNet", "是否网销"}, {"FIsAutoAllocate", "自动分配"}, {"FSPUID", "SPU信息"}, {"FPinYin", "拼音"}, {"FDSMatchByLot", "按批号匹配供需"},
	// 	{"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}}
	fieldKeys := []string{
		"FMATERIALID", "FSpecification", "FName", "FNumber",
		"FDocumentStatus", "FForbidStatus", "FErpClsID",
		"FBaseUnitId", "FBaseUnitId.FName", "FCreateDate", "FModifyDate",
		"FForbidDate", "FApproveDate", "FMaterialGroup", "FMaterialGroup.FName",
		"FRefStatus", "FMaterialGroup.FNumber", "FUseOrgId", "FUseOrgId.FName",
	}
	result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{
		FormId: "BD_MATERIAL",
		Data: ExecuteBillQueryData{
			FormId:       "BD_MATERIAL",
			FieldKeys:    strings.Join(fieldKeys, ","), //查询的字段
			TopRowCount:  5,
			FilterString: "",
		},
	})
	t.Logf("result buf===> %s \n", string(result.Buf))
	if err != nil {
		t.Error(err)
		return
	}
}

func TestExecuteBillQuery2(t *testing.T) {
	client, err := NewClient(hostUrl, acctID, username, password)
	if err != nil {
		t.Error(err)
		return
	}
	fieldKeys := []string{
		"FBillNo", "FWorkShopID", "FWorkShopID.FName", "FMaterialId", "FMaterialId.FName",
		"FMaterialId.FNumber", "FMaterialId.FSpecification", "FPlanStartDate", "FPlanFinishDate", "FDate", "FQty",
		"FCreateDate", "FModifyDate", "FPrdOrgId", "FPrdOrgId.FName", "FRowId", "FUnitId", "FUnitId.FName", "FDescription",
	}
	result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{
		FormId: "PRD_MO",
		Data: ExecuteBillQueryData{
			FormId:      "PRD_MO",
			FieldKeys:   strings.Join(fieldKeys, ","), //查询的字段
			TopRowCount: 4,

			FilterString: "",
		},
	})
	t.Logf("result buf===> %s \n", string(result.Buf))
	if err != nil {
		t.Error(err)
		return
	}
}