作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-manufacture into dev
@@ -62,7 +62,7 @@ func (c *Client) Login(acctID string, username string, password string, lcid ... @@ -62,7 +62,7 @@ func (c *Client) Login(acctID string, username string, password string, lcid ...
62 } 62 }
63 63
64 // ExecuteBillQuery 单据查询 64 // ExecuteBillQuery 单据查询
65 -func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*QueryResult, error) { 65 +func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResult, error) {
66 api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc" 66 api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc"
67 paramFomat := []interface{}{param} 67 paramFomat := []interface{}{param}
68 resp, err := c.PostRequest(api, paramFomat) 68 resp, err := c.PostRequest(api, paramFomat)
@@ -75,6 +75,11 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*QueryResult, @@ -75,6 +75,11 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*QueryResult,
75 if err != nil { 75 if err != nil {
76 return nil, err 76 return nil, err
77 } 77 }
78 - queryResult := newQueryResult(dataByte, param.FieldKeys) 78 + queryResult := newBillQueryResult(dataByte, param.FieldKeys)
79 return queryResult, queryResult.Error() 79 return queryResult, queryResult.Error()
80 } 80 }
  81 +
  82 +//QueryGroupInfo 分组信息查询
  83 +func (c *Client) QueryGroupInfo() {
  84 +
  85 +}
@@ -36,7 +36,7 @@ func TestExecuteBillQuery(t *testing.T) { @@ -36,7 +36,7 @@ func TestExecuteBillQuery(t *testing.T) {
36 // {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}} 36 // {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}}
37 result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ 37 result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{
38 FormId: "BD_MATERIAL", //物料 38 FormId: "BD_MATERIAL", //物料
39 - FieldKeys: "FMATERIALID,FName,FNumber,FUseOrgId,FModifyDate,FCreateDate,FApproveDate", //查询的字段 39 + FieldKeys: "FMATERIALID,FDocumentStatus,FName,FNumber,FModifyDate,FBaseUnitId.FName,FUseOrgId.FName,FMaterialGroup.FName", //查询的字段
40 TopRowCount: 5, 40 TopRowCount: 5,
41 }) 41 })
42 t.Logf("result buf===> %s \n", string(result.Buf)) 42 t.Logf("result buf===> %s \n", string(result.Buf))
1 -package k3cloud  
2 -  
3 -import (  
4 - "encoding/json"  
5 - "log"  
6 - "testing"  
7 -  
8 - "github.com/tidwall/gjson"  
9 -)  
10 -  
11 -func TestDecodeJson1(t *testing.T) {  
12 - //  
13 - str := `[[{"Result":{"ResponseStatus":{"ErrorCode":500,"IsSuccess":false,"Errors":[{"FieldName":null,"Message":"元数据中标识为FUseOrg的字段不存在","DIndex":0}],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":9}}}]]`  
14 - jResult := gjson.Parse(str)  
15 - arr1 := jResult.Array()  
16 - if len(arr1) == 0 {  
17 - return  
18 - }  
19 - arr2 := arr1[0].Array()  
20 - if len(arr2) == 0 {  
21 - return  
22 - }  
23 - var errResult QueryError  
24 - if !arr2[0].IsObject() {  
25 - return  
26 - }  
27 - rw := arr2[0].Raw  
28 - err := json.Unmarshal([]byte(rw), &errResult)  
29 - if err != nil {  
30 - return  
31 - }  
32 - log.Println(errResult)  
33 -}  
34 -  
35 -func TestDecodeJson2(t *testing.T) {  
36 - str := `[["xxx","abc",2345]]`  
37 - jResult := gjson.Parse(str)  
38 - jResult.ForEach(func(key, value1 gjson.Result) bool {  
39 - value1.ForEach(func(key, value2 gjson.Result) bool {  
40 - log.Println(key.Int(), value2.String())  
41 - return true  
42 - })  
43 - return true  
44 - })  
45 -  
46 -}  
@@ -30,26 +30,25 @@ func (qe QueryError) Error() string { @@ -30,26 +30,25 @@ func (qe QueryError) Error() string {
30 return str 30 return str
31 } 31 }
32 32
33 -/*QueryResult 单据查询结果 33 +/*BillQueryResult 单据查询结果
34 当接口调用失败时得到的json 结构对应[][]QueryError,如: 34 当接口调用失败时得到的json 结构对应[][]QueryError,如:
35 [[{"Result":{"ResponseStatus":{"Errors":[{"Message":"元数据中标识为FUseOrg的字段不存在"}]}}}]] 35 [[{"Result":{"ResponseStatus":{"Errors":[{"Message":"元数据中标识为FUseOrg的字段不存在"}]}}}]]
36 当接口调用成功的得到的json结构对应[][]interface{},如: 36 当接口调用成功的得到的json结构对应[][]interface{},如:
37 [["xxx","abc",2345]] 37 [["xxx","abc",2345]]
38 */ 38 */
39 -type QueryResult struct { 39 +type BillQueryResult struct {
40 FieldKeys []string //对应的键名 ,注意数据的顺序 40 FieldKeys []string //对应的键名 ,注意数据的顺序
41 Buf []byte //原始的数据byte 41 Buf []byte //原始的数据byte
42 -  
43 } 42 }
44 43
45 -func newQueryResult(buf []byte, keys string) *QueryResult {  
46 - return &QueryResult{ 44 +func newBillQueryResult(buf []byte, keys string) *BillQueryResult {
  45 + return &BillQueryResult{
47 Buf: buf, 46 Buf: buf,
48 FieldKeys: strings.Split(keys, ","), 47 FieldKeys: strings.Split(keys, ","),
49 } 48 }
50 } 49 }
51 50
52 -func (result *QueryResult) ToMapString() []map[string]string { 51 +func (result *BillQueryResult) ToMapString() []map[string]string {
53 if result.IsError() { 52 if result.IsError() {
54 return nil 53 return nil
55 } 54 }
@@ -70,7 +69,7 @@ func (result *QueryResult) ToMapString() []map[string]string { @@ -70,7 +69,7 @@ func (result *QueryResult) ToMapString() []map[string]string {
70 return mapResult 69 return mapResult
71 } 70 }
72 71
73 -func (result *QueryResult) ToMap() []map[string]interface{} { 72 +func (result *BillQueryResult) ToMap() []map[string]interface{} {
74 if result.IsError() { 73 if result.IsError() {
75 return nil 74 return nil
76 } 75 }
@@ -91,7 +90,7 @@ func (result *QueryResult) ToMap() []map[string]interface{} { @@ -91,7 +90,7 @@ func (result *QueryResult) ToMap() []map[string]interface{} {
91 return mapResult 90 return mapResult
92 } 91 }
93 92
94 -func (result *QueryResult) Error() error { 93 +func (result *BillQueryResult) Error() error {
95 var ( 94 var (
96 errMsg QueryError 95 errMsg QueryError
97 err error 96 err error
@@ -112,11 +111,11 @@ func (result *QueryResult) Error() error { @@ -112,11 +111,11 @@ func (result *QueryResult) Error() error {
112 } 111 }
113 112
114 //TODO 将结果解析为结构体 113 //TODO 将结果解析为结构体
115 -// func (result *QueryResult) ToStruct(v interface{}) error { 114 +// func (result *BillQueryResult) ToStruct(v interface{}) error {
116 // return nil 115 // return nil
117 // } 116 // }
118 117
119 -func (result *QueryResult) IsError() bool { 118 +func (result *BillQueryResult) IsError() bool {
120 jResult := gjson.ParseBytes(result.Buf) 119 jResult := gjson.ParseBytes(result.Buf)
121 for _, arr1 := range jResult.Array() { 120 for _, arr1 := range jResult.Array() {
122 for _, item := range arr1.Array() { 121 for _, item := range arr1.Array() {
  1 +package k3cloud
  2 +
  3 +import "testing"
  4 +
  5 +func TestErrorResult(t *testing.T) {
  6 + jsonByte := []byte(`[[{"Result":{"ResponseStatus":{"ErrorCode":500,"IsSuccess":false,"Errors":[{"FieldName":null,"Message":"元数据中标识为FUseOrg的字段不存在","DIndex":0}],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":9}}}]]`)
  7 + result := newBillQueryResult(jsonByte, "")
  8 + if !result.IsError() {
  9 + t.Error("没有正确识别错误的消息数据")
  10 + return
  11 + }
  12 + m := result.ToMap()
  13 + if len(m) > 0 {
  14 + t.Error("解析了错误的数据")
  15 + return
  16 + }
  17 + e := result.Error()
  18 + if e == nil {
  19 + t.Error("没有正常的获得错误信息")
  20 + return
  21 + }
  22 + t.Logf("%v", result.Error())
  23 +}
  24 +
  25 +func TestRightResult(t *testing.T) {
  26 + jsonByte := []byte(`[["xxx","abc",2345],["xxa","abc1",23457],["xxb","abc2",23458]]`)
  27 + result := newBillQueryResult(jsonByte, "name,desc,number")
  28 + if result.IsError() {
  29 + t.Error("数据解析失败")
  30 + return
  31 + }
  32 + m := result.ToMapString()
  33 + if len(m) == 0 {
  34 + t.Error("没有返回数据")
  35 + return
  36 + }
  37 + t.Logf("%v", m)
  38 +}
  1 +## API
  2 +
  3 +| 名称 | 链接 |
  4 +| -------------- | ---------------------------------------------------------------------------------- |
  5 +| _登陆验证接口_ | /Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc |
  6 +| _单据查询_ | /Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc |
  7 +| _元数据查询_ | /Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo.common.kdsvc |
  8 +| | |
  9 +| | |
  10 +
  11 +## FORMID
  12 +
  13 +| FORMID | 模块 | 备注 |
  14 +| :---------------- | --------------------------- | ---- |
  15 +| BD_MATERIAL | 基础管理-基础资料-物料 | |
  16 +| SAL_MATERIALGROUP | 基础管理-基础资料-物料-分组 | |
  17 +| | | |
  18 +
  19 +## 物料字段描述(部分)
  20 +
  21 +| 字段名 | 备注 |
  22 +| -------------------- | ------------------------------------------------------------------------------------------------------------- |
  23 +| FMATERIALID | 物料表主键 |
  24 +| FDocumentStatus | _数据状态,对应描述如下_ _"Z":暂存,"A":创建,"B":审核中,"C":已审核,"D":重新审核_ |
  25 +| FName | _物料名称_ |
  26 +| FNumber | _物料编码_ |
  27 +| FSpecification | _规格型号_ |
  28 +| FForbidStatus | _禁用状态,对应描述如下_"A":否,"B":是 |
  29 +| FErpClsID | _物料属性_ _10:资产,9:配置,2:自制,11:费用,12:模型,5:虚拟,7:一次性_ _12:产品系列,3:委外,4:特征,6:服务,1:外购_ |
  30 +| FBaseUnitId | _基本单位 id_ |
  31 +| FBaseUnitId.FName | _基本单位名称_ |
  32 +| FCreateDate | _创建日期 如:"2022-01-08T19:36:06.843"_ |
  33 +| FModifyDate | _修改日期 如: "2022-01-08T19:36:06.843"_ |
  34 +| FForbidDate | _禁用日期 如:"2022-01-08T19:36:06.843"_ |
  35 +| FApproveDate | _审核日期 如:"2022-01-08T19:36:06.843"_ |
  36 +| FMaterialGroup | _物料分组 id_ |
  37 +| FMaterialGroup.FName | _物料分组名称_ |
  38 +| FRefStatus | _是否使用_ _1:是,0:否_ |
  39 +| | |
  40 +
  41 +### 分组列表字段描述
  42 +
  43 +| 字段名 | 备注 | 类型 |
  44 +| --------- | --------- | -------- |
  45 +| FID | 表主键 id | 整型数字 |
  46 +| FNumber | 分组编码 | 字符串 |
  47 +| FName | 分组名称 | 字符串 |
  48 +| FParentId | 上级分组 | 字符串 |
  49 +| | | |