作者 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 ...
}
// ExecuteBillQuery 单据查询
func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*QueryResult, error) {
func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResult, error) {
api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc"
paramFomat := []interface{}{param}
resp, err := c.PostRequest(api, paramFomat)
... ... @@ -75,6 +75,11 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*QueryResult,
if err != nil {
return nil, err
}
queryResult := newQueryResult(dataByte, param.FieldKeys)
queryResult := newBillQueryResult(dataByte, param.FieldKeys)
return queryResult, queryResult.Error()
}
//QueryGroupInfo 分组信息查询
func (c *Client) QueryGroupInfo() {
}
... ...
... ... @@ -35,8 +35,8 @@ func TestExecuteBillQuery(t *testing.T) {
// {"FIsSalseByNet", "是否网销"}, {"FIsAutoAllocate", "自动分配"}, {"FSPUID", "SPU信息"}, {"FPinYin", "拼音"}, {"FDSMatchByLot", "按批号匹配供需"},
// {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}}
result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{
FormId: "BD_MATERIAL", //物料
FieldKeys: "FMATERIALID,FName,FNumber,FUseOrgId,FModifyDate,FCreateDate,FApproveDate", //查询的字段
FormId: "BD_MATERIAL", //物料
FieldKeys: "FMATERIALID,FDocumentStatus,FName,FNumber,FModifyDate,FBaseUnitId.FName,FUseOrgId.FName,FMaterialGroup.FName", //查询的字段
TopRowCount: 5,
})
t.Logf("result buf===> %s \n", string(result.Buf))
... ...
package k3cloud
import (
"encoding/json"
"log"
"testing"
"github.com/tidwall/gjson"
)
func TestDecodeJson1(t *testing.T) {
//
str := `[[{"Result":{"ResponseStatus":{"ErrorCode":500,"IsSuccess":false,"Errors":[{"FieldName":null,"Message":"元数据中标识为FUseOrg的字段不存在","DIndex":0}],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":9}}}]]`
jResult := gjson.Parse(str)
arr1 := jResult.Array()
if len(arr1) == 0 {
return
}
arr2 := arr1[0].Array()
if len(arr2) == 0 {
return
}
var errResult QueryError
if !arr2[0].IsObject() {
return
}
rw := arr2[0].Raw
err := json.Unmarshal([]byte(rw), &errResult)
if err != nil {
return
}
log.Println(errResult)
}
func TestDecodeJson2(t *testing.T) {
str := `[["xxx","abc",2345]]`
jResult := gjson.Parse(str)
jResult.ForEach(func(key, value1 gjson.Result) bool {
value1.ForEach(func(key, value2 gjson.Result) bool {
log.Println(key.Int(), value2.String())
return true
})
return true
})
}
... ... @@ -30,26 +30,25 @@ func (qe QueryError) Error() string {
return str
}
/*QueryResult 单据查询结果
/*BillQueryResult 单据查询结果
当接口调用失败时得到的json 结构对应[][]QueryError,如:
[[{"Result":{"ResponseStatus":{"Errors":[{"Message":"元数据中标识为FUseOrg的字段不存在"}]}}}]]
当接口调用成功的得到的json结构对应[][]interface{},如:
[["xxx","abc",2345]]
*/
type QueryResult struct {
type BillQueryResult struct {
FieldKeys []string //对应的键名 ,注意数据的顺序
Buf []byte //原始的数据byte
}
func newQueryResult(buf []byte, keys string) *QueryResult {
return &QueryResult{
func newBillQueryResult(buf []byte, keys string) *BillQueryResult {
return &BillQueryResult{
Buf: buf,
FieldKeys: strings.Split(keys, ","),
}
}
func (result *QueryResult) ToMapString() []map[string]string {
func (result *BillQueryResult) ToMapString() []map[string]string {
if result.IsError() {
return nil
}
... ... @@ -70,7 +69,7 @@ func (result *QueryResult) ToMapString() []map[string]string {
return mapResult
}
func (result *QueryResult) ToMap() []map[string]interface{} {
func (result *BillQueryResult) ToMap() []map[string]interface{} {
if result.IsError() {
return nil
}
... ... @@ -91,7 +90,7 @@ func (result *QueryResult) ToMap() []map[string]interface{} {
return mapResult
}
func (result *QueryResult) Error() error {
func (result *BillQueryResult) Error() error {
var (
errMsg QueryError
err error
... ... @@ -112,11 +111,11 @@ func (result *QueryResult) Error() error {
}
//TODO 将结果解析为结构体
// func (result *QueryResult) ToStruct(v interface{}) error {
// func (result *BillQueryResult) ToStruct(v interface{}) error {
// return nil
// }
func (result *QueryResult) IsError() bool {
func (result *BillQueryResult) IsError() bool {
jResult := gjson.ParseBytes(result.Buf)
for _, arr1 := range jResult.Array() {
for _, item := range arr1.Array() {
... ...
package k3cloud
import "testing"
func TestErrorResult(t *testing.T) {
jsonByte := []byte(`[[{"Result":{"ResponseStatus":{"ErrorCode":500,"IsSuccess":false,"Errors":[{"FieldName":null,"Message":"元数据中标识为FUseOrg的字段不存在","DIndex":0}],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":9}}}]]`)
result := newBillQueryResult(jsonByte, "")
if !result.IsError() {
t.Error("没有正确识别错误的消息数据")
return
}
m := result.ToMap()
if len(m) > 0 {
t.Error("解析了错误的数据")
return
}
e := result.Error()
if e == nil {
t.Error("没有正常的获得错误信息")
return
}
t.Logf("%v", result.Error())
}
func TestRightResult(t *testing.T) {
jsonByte := []byte(`[["xxx","abc",2345],["xxa","abc1",23457],["xxb","abc2",23458]]`)
result := newBillQueryResult(jsonByte, "name,desc,number")
if result.IsError() {
t.Error("数据解析失败")
return
}
m := result.ToMapString()
if len(m) == 0 {
t.Error("没有返回数据")
return
}
t.Logf("%v", m)
}
... ...
## API
| 名称 | 链接 |
| -------------- | ---------------------------------------------------------------------------------- |
| _登陆验证接口_ | /Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc |
| _单据查询_ | /Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc |
| _元数据查询_ | /Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo.common.kdsvc |
| | |
| | |
## FORMID
| FORMID | 模块 | 备注 |
| :---------------- | --------------------------- | ---- |
| BD_MATERIAL | 基础管理-基础资料-物料 | |
| SAL_MATERIALGROUP | 基础管理-基础资料-物料-分组 | |
| | | |
## 物料字段描述(部分)
| 字段名 | 备注 |
| -------------------- | ------------------------------------------------------------------------------------------------------------- |
| FMATERIALID | 物料表主键 |
| FDocumentStatus | _数据状态,对应描述如下_ _"Z":暂存,"A":创建,"B":审核中,"C":已审核,"D":重新审核_ |
| FName | _物料名称_ |
| FNumber | _物料编码_ |
| FSpecification | _规格型号_ |
| FForbidStatus | _禁用状态,对应描述如下_"A":否,"B":是 |
| FErpClsID | _物料属性_ _10:资产,9:配置,2:自制,11:费用,12:模型,5:虚拟,7:一次性_ _12:产品系列,3:委外,4:特征,6:服务,1:外购_ |
| FBaseUnitId | _基本单位 id_ |
| FBaseUnitId.FName | _基本单位名称_ |
| FCreateDate | _创建日期 如:"2022-01-08T19:36:06.843"_ |
| FModifyDate | _修改日期 如: "2022-01-08T19:36:06.843"_ |
| FForbidDate | _禁用日期 如:"2022-01-08T19:36:06.843"_ |
| FApproveDate | _审核日期 如:"2022-01-08T19:36:06.843"_ |
| FMaterialGroup | _物料分组 id_ |
| FMaterialGroup.FName | _物料分组名称_ |
| FRefStatus | _是否使用_ _1:是,0:否_ |
| | |
### 分组列表字段描述
| 字段名 | 备注 | 类型 |
| --------- | --------- | -------- |
| FID | 表主键 id | 整型数字 |
| FNumber | 分组编码 | 字符串 |
| FName | 分组名称 | 字符串 |
| FParentId | 上级分组 | 字符串 |
| | | |
... ...