正在显示
9 个修改的文件
包含
441 行增加
和
0 行删除
| @@ -11,6 +11,7 @@ require ( | @@ -11,6 +11,7 @@ require ( | ||
| 11 | github.com/go-pg/pg/v10 v10.9.0 | 11 | github.com/go-pg/pg/v10 v10.9.0 |
| 12 | github.com/go-redis/redis v6.15.7+incompatible | 12 | github.com/go-redis/redis v6.15.7+incompatible |
| 13 | github.com/google/go-querystring v1.1.0 // indirect | 13 | github.com/google/go-querystring v1.1.0 // indirect |
| 14 | + github.com/google/uuid v1.3.0 // indirect | ||
| 14 | github.com/imkira/go-interpol v1.1.0 // indirect | 15 | github.com/imkira/go-interpol v1.1.0 // indirect |
| 15 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | 16 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 |
| 16 | github.com/moul/http2curl v1.0.0 // indirect | 17 | github.com/moul/http2curl v1.0.0 // indirect |
| @@ -19,6 +20,7 @@ require ( | @@ -19,6 +20,7 @@ require ( | ||
| 19 | github.com/sergi/go-diff v1.2.0 // indirect | 20 | github.com/sergi/go-diff v1.2.0 // indirect |
| 20 | github.com/smartystreets/goconvey v1.7.2 // indirect | 21 | github.com/smartystreets/goconvey v1.7.2 // indirect |
| 21 | github.com/stretchr/testify v1.7.0 | 22 | github.com/stretchr/testify v1.7.0 |
| 23 | + github.com/tidwall/gjson v1.13.0 // indirect | ||
| 22 | github.com/valyala/fasthttp v1.32.0 // indirect | 24 | github.com/valyala/fasthttp v1.32.0 // indirect |
| 23 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect | 25 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect |
| 24 | github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect | 26 | github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect |
| @@ -162,6 +162,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 | @@ -162,6 +162,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 | ||
| 162 | github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | 162 | github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
| 163 | github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | 163 | github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= |
| 164 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | 164 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
| 165 | +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= | ||
| 166 | +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| 165 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= | 167 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= |
| 166 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= | 168 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= |
| 167 | github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= | 169 | github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= |
| @@ -351,6 +353,12 @@ github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2K | @@ -351,6 +353,12 @@ github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2K | ||
| 351 | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= | 353 | github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= |
| 352 | github.com/tal-tech/go-zero v1.0.27 h1:QMIbaTxibMc/OsO5RTAuKZ8ndbl2dGN6pITQEtp2x/A= | 354 | github.com/tal-tech/go-zero v1.0.27 h1:QMIbaTxibMc/OsO5RTAuKZ8ndbl2dGN6pITQEtp2x/A= |
| 353 | github.com/tal-tech/go-zero v1.0.27/go.mod h1:JtNXlsh/CgeIHyQnt5C5M2IcSevW7V0NAnqO93TQgm8= | 355 | github.com/tal-tech/go-zero v1.0.27/go.mod h1:JtNXlsh/CgeIHyQnt5C5M2IcSevW7V0NAnqO93TQgm8= |
| 356 | +github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= | ||
| 357 | +github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= | ||
| 358 | +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | ||
| 359 | +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= | ||
| 360 | +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= | ||
| 361 | +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= | ||
| 354 | github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987 h1:0e2hOSL+//5AL7e1r3xCGEugsOPsw2POAm82VZvWLe4= | 362 | github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987 h1:0e2hOSL+//5AL7e1r3xCGEugsOPsw2POAm82VZvWLe4= |
| 355 | github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987/go.mod h1:xl9i83IKNUkwlobRF6XLKn1RRbZsT+7yhCicpTGWTKc= | 363 | github.com/tiptok/egglib-go v0.0.0-20220120032512-24dfab2b4987/go.mod h1:xl9i83IKNUkwlobRF6XLKn1RRbZsT+7yhCicpTGWTKc= |
| 356 | github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | 364 | github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= |
pkg/infrastructure/utils/k3cloud/client.go
0 → 100644
| 1 | +package k3cloud | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + "io" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +//初始化默认的客户端 | ||
| 9 | + | ||
| 10 | +type Client struct { | ||
| 11 | + HttpClient | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +/*NewClient 新建客户端, | ||
| 15 | +默认执行登录操作,填充cookie | ||
| 16 | +*/ | ||
| 17 | +func NewClient(apihost string, acctID string, username string, password string, lcid ...int) (*Client, error) { | ||
| 18 | + client := &Client{ | ||
| 19 | + HttpClient{ | ||
| 20 | + HostUrl: apihost, | ||
| 21 | + }, | ||
| 22 | + } | ||
| 23 | + _, err := client.Login(acctID, username, password, lcid...) | ||
| 24 | + if err != nil { | ||
| 25 | + return nil, err | ||
| 26 | + } | ||
| 27 | + return client, nil | ||
| 28 | + | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +/* | ||
| 32 | +Login 登陆验证接口 | ||
| 33 | +acctID 账套Id, | ||
| 34 | +username 密码 | ||
| 35 | +password 用户登陆名 | ||
| 36 | +lcid 语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307 | ||
| 37 | +*/ | ||
| 38 | +func (c *Client) Login(acctID string, username string, password string, lcid ...int) (*ReponseValidateUser, error) { | ||
| 39 | + api := "/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc" | ||
| 40 | + lcidTemp := 2052 | ||
| 41 | + if len(lcid) > 0 { | ||
| 42 | + lcidTemp = lcid[0] | ||
| 43 | + } | ||
| 44 | + param := []interface{}{acctID, username, password, lcidTemp} | ||
| 45 | + resp, err := c.PostRequest(api, param) | ||
| 46 | + if err != nil { | ||
| 47 | + return nil, err | ||
| 48 | + } | ||
| 49 | + defer resp.Body.Close() | ||
| 50 | + cookies := resp.Cookies() | ||
| 51 | + //填充调用接口时需要的cookie | ||
| 52 | + c.HttpClient.Cookie = cookies | ||
| 53 | + var loginReturn ReponseValidateUser | ||
| 54 | + err = c.DecodeJSON(resp.Body, &loginReturn) | ||
| 55 | + if err != nil { | ||
| 56 | + return nil, err | ||
| 57 | + } | ||
| 58 | + if loginReturn.LoginResultType != 1 { | ||
| 59 | + return &loginReturn, errors.New(loginReturn.Message) | ||
| 60 | + } | ||
| 61 | + return &loginReturn, nil | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +// ExecuteBillQuery 单据查询 | ||
| 65 | +func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*QueryResult, error) { | ||
| 66 | + api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc" | ||
| 67 | + paramFomat := []interface{}{param} | ||
| 68 | + resp, err := c.PostRequest(api, paramFomat) | ||
| 69 | + if err != nil { | ||
| 70 | + return nil, err | ||
| 71 | + } | ||
| 72 | + defer resp.Body.Close() | ||
| 73 | + var dataByte []byte | ||
| 74 | + dataByte, err = io.ReadAll(resp.Body) | ||
| 75 | + if err != nil { | ||
| 76 | + return nil, err | ||
| 77 | + } | ||
| 78 | + queryResult := newQueryResult(dataByte, param.FieldKeys) | ||
| 79 | + return queryResult, queryResult.Error() | ||
| 80 | +} |
| 1 | +package k3cloud | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "testing" | ||
| 5 | +) | ||
| 6 | + | ||
| 7 | +var ( | ||
| 8 | + acctID = "20211118121754866" | ||
| 9 | + // username = "Administrator" | ||
| 10 | + // password = "stxcs@888" | ||
| 11 | + username = "18559023318" | ||
| 12 | + password = "stx@123456" | ||
| 13 | + hostUrl = "https://tianlian.test.ik3cloud.com/k3cloud" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +func TestLogin(t *testing.T) { | ||
| 17 | + client := Client{HttpClient{HostUrl: hostUrl}} | ||
| 18 | + result, err := client.Login(acctID, username, password) | ||
| 19 | + if err != nil { | ||
| 20 | + t.Error(err) | ||
| 21 | + } | ||
| 22 | + t.Logf("%+v \n", *result) | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func TestExecuteBillQuery(t *testing.T) { | ||
| 26 | + client, err := NewClient(hostUrl, acctID, username, password) | ||
| 27 | + if err != nil { | ||
| 28 | + t.Error(err) | ||
| 29 | + return | ||
| 30 | + } | ||
| 31 | + //参见 物料元数据 | ||
| 32 | + // _ = [][2]string{{"FMATERIALID", "表主键"}, {"FDocumentStatus", "数据状态"}, {"FForbidStatus", "禁用状态"}, {"FName", "名称"}, {"FNumber", "编码"}, {"FDescription", "描述"}, | ||
| 33 | + // {"FCreateDate", "创建日期"}, {"FModifyDate", "修改日期"}, {"FMnemonicCode", "助记码"}, {"FSpecification", "规格型号"}, {"FForbidDate", "禁用日期"}, | ||
| 34 | + // {"FApproveDate", "审核日期"}, {"FOldNumber", "旧物料编码"}, {"FMaterialGroup", "物料分组"}, {"FPLMMaterialId", "PLM物料内码"}, {"FMaterialSRC", "物料来源"}, | ||
| 35 | + // {"FIsSalseByNet", "是否网销"}, {"FIsAutoAllocate", "自动分配"}, {"FSPUID", "SPU信息"}, {"FPinYin", "拼音"}, {"FDSMatchByLot", "按批号匹配供需"}, | ||
| 36 | + // {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}} | ||
| 37 | + result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ | ||
| 38 | + FormId: "BD_MATERIAL", //物料 | ||
| 39 | + FieldKeys: "FMATERIALID,FName,FNumber,FUseOrgId,FModifyDate,FCreateDate,FApproveDate", //查询的字段 | ||
| 40 | + TopRowCount: 5, | ||
| 41 | + }) | ||
| 42 | + t.Logf("result buf===> %s \n", string(result.Buf)) | ||
| 43 | + if err != nil { | ||
| 44 | + t.Error(err) | ||
| 45 | + return | ||
| 46 | + } | ||
| 47 | + t.Logf("tomap===>%v \n", result.ToMapString()) | ||
| 48 | +} |
| 1 | +package k3cloud | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "bytes" | ||
| 5 | + "encoding/json" | ||
| 6 | + "fmt" | ||
| 7 | + "io" | ||
| 8 | + "net/http" | ||
| 9 | + "time" | ||
| 10 | + | ||
| 11 | + "github.com/google/uuid" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +//全局使用的http请求 | ||
| 15 | +type HttpClient struct { | ||
| 16 | + HostUrl string | ||
| 17 | + Cookie []*http.Cookie | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +//WrapPostData 包装发送的数据 | ||
| 21 | +func (hClient *HttpClient) WrapPostData(param interface{}) (*postData, error) { | ||
| 22 | + data := postData{ | ||
| 23 | + Format: 1, | ||
| 24 | + Useragent: "ApiClient", | ||
| 25 | + Rid: uuid.NewString(), | ||
| 26 | + Timestamp: time.Now().Format("2006-01-02"), | ||
| 27 | + V: "1.0", | ||
| 28 | + Parameters: param, | ||
| 29 | + } | ||
| 30 | + return &data, nil | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func (hClient *HttpClient) PostRequest(api string, param interface{}) (*http.Response, error) { | ||
| 34 | + data, err := hClient.WrapPostData(param) | ||
| 35 | + if err != nil { | ||
| 36 | + return nil, err | ||
| 37 | + } | ||
| 38 | + url := fmt.Sprintf("%s%s", hClient.HostUrl, api) | ||
| 39 | + var buf bytes.Buffer | ||
| 40 | + encoder := json.NewEncoder(&buf) | ||
| 41 | + err = encoder.Encode(data) | ||
| 42 | + if err != nil { | ||
| 43 | + return nil, err | ||
| 44 | + } | ||
| 45 | + req, err := http.NewRequest(http.MethodPost, url, &buf) | ||
| 46 | + if err != nil { | ||
| 47 | + return nil, err | ||
| 48 | + } | ||
| 49 | + req.Header.Set("Content-Type", "application/json") | ||
| 50 | + for i := range hClient.Cookie { | ||
| 51 | + req.AddCookie(hClient.Cookie[i]) | ||
| 52 | + } | ||
| 53 | + client := http.Client{ | ||
| 54 | + Timeout: 60 * time.Second, | ||
| 55 | + } | ||
| 56 | + resp, err := client.Do(req) | ||
| 57 | + if err != nil { | ||
| 58 | + return nil, err | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + return resp, err | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +func (hClient *HttpClient) DecodeJSON(r io.Reader, v interface{}) error { | ||
| 65 | + defer io.Copy(io.Discard, r) | ||
| 66 | + return json.NewDecoder(r).Decode(v) | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +func (hClient *HttpClient) InvokeApi(api string, param interface{}, respData interface{}) error { | ||
| 70 | + resp, err := hClient.PostRequest(api, param) | ||
| 71 | + if err != nil { | ||
| 72 | + return err | ||
| 73 | + } | ||
| 74 | + err = hClient.DecodeJSON(resp.Body, respData) | ||
| 75 | + return err | ||
| 76 | +} |
| 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 | +} |
| 1 | +package k3cloud | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "strings" | ||
| 6 | + | ||
| 7 | + "github.com/tidwall/gjson" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +//QueryError 单据查询错误信息 | ||
| 11 | +type QueryError struct { | ||
| 12 | + Result struct { | ||
| 13 | + ResponseStatus struct { | ||
| 14 | + ErrorCode int `json:"ErrorCode"` | ||
| 15 | + IsSuccess bool `json:"IsSuccess"` | ||
| 16 | + Errors []struct { | ||
| 17 | + FieldName interface{} `json:"FieldName"` | ||
| 18 | + Message string `json:"Message"` | ||
| 19 | + DIndex int `json:"DIndex"` | ||
| 20 | + } `json:"Errors"` | ||
| 21 | + } `json:"ResponseStatus"` | ||
| 22 | + } `json:"Result"` | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func (qe QueryError) Error() string { | ||
| 26 | + str := "" | ||
| 27 | + for _, errMsg := range qe.Result.ResponseStatus.Errors { | ||
| 28 | + str += errMsg.Message + ";" | ||
| 29 | + } | ||
| 30 | + return str | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +/*QueryResult 单据查询结果 | ||
| 34 | +当接口调用失败时得到的json 结构对应[][]QueryError,如: | ||
| 35 | +[[{"Result":{"ResponseStatus":{"Errors":[{"Message":"元数据中标识为FUseOrg的字段不存在"}]}}}]] | ||
| 36 | +当接口调用成功的得到的json结构对应[][]interface{},如: | ||
| 37 | +[["xxx","abc",2345]] | ||
| 38 | +*/ | ||
| 39 | +type QueryResult struct { | ||
| 40 | + FieldKeys []string //对应的键名 ,注意数据的顺序 | ||
| 41 | + Buf []byte //原始的数据byte | ||
| 42 | + | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +func newQueryResult(buf []byte, keys string) *QueryResult { | ||
| 46 | + return &QueryResult{ | ||
| 47 | + Buf: buf, | ||
| 48 | + FieldKeys: strings.Split(keys, ","), | ||
| 49 | + } | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +func (result *QueryResult) ToMapString() []map[string]string { | ||
| 53 | + if result.IsError() { | ||
| 54 | + return nil | ||
| 55 | + } | ||
| 56 | + jResult := gjson.ParseBytes(result.Buf) | ||
| 57 | + mapResult := []map[string]string{} | ||
| 58 | + var mapTemp map[string]string | ||
| 59 | + for _, arr1 := range jResult.Array() { | ||
| 60 | + mapTemp = make(map[string]string) | ||
| 61 | + for index2, item := range arr1.Array() { | ||
| 62 | + if index2 > len(result.FieldKeys) { | ||
| 63 | + continue | ||
| 64 | + } | ||
| 65 | + keyName := result.FieldKeys[index2] | ||
| 66 | + mapTemp[keyName] = item.String() | ||
| 67 | + } | ||
| 68 | + mapResult = append(mapResult, mapTemp) | ||
| 69 | + } | ||
| 70 | + return mapResult | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +func (result *QueryResult) ToMap() []map[string]interface{} { | ||
| 74 | + if result.IsError() { | ||
| 75 | + return nil | ||
| 76 | + } | ||
| 77 | + jResult := gjson.ParseBytes(result.Buf) | ||
| 78 | + mapResult := []map[string]interface{}{} | ||
| 79 | + var mapTemp map[string]interface{} | ||
| 80 | + for _, arr1 := range jResult.Array() { | ||
| 81 | + mapTemp = make(map[string]interface{}) | ||
| 82 | + for index2, item := range arr1.Array() { | ||
| 83 | + if index2 > len(result.FieldKeys) { | ||
| 84 | + continue | ||
| 85 | + } | ||
| 86 | + keyName := result.FieldKeys[index2] | ||
| 87 | + mapTemp[keyName] = item.Value() | ||
| 88 | + } | ||
| 89 | + mapResult = append(mapResult, mapTemp) | ||
| 90 | + } | ||
| 91 | + return mapResult | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +func (result *QueryResult) Error() error { | ||
| 95 | + var ( | ||
| 96 | + errMsg QueryError | ||
| 97 | + err error | ||
| 98 | + ) | ||
| 99 | + jResult := gjson.ParseBytes(result.Buf) | ||
| 100 | + for _, arr1 := range jResult.Array() { | ||
| 101 | + for _, item := range arr1.Array() { | ||
| 102 | + if !item.IsObject() { | ||
| 103 | + return nil | ||
| 104 | + } | ||
| 105 | + err = json.Unmarshal([]byte(item.Raw), &errMsg) | ||
| 106 | + if err != nil { | ||
| 107 | + return err | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + return errMsg | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +//TODO 将结果解析为结构体 | ||
| 115 | +// func (result *QueryResult) ToStruct(v interface{}) error { | ||
| 116 | +// return nil | ||
| 117 | +// } | ||
| 118 | + | ||
| 119 | +func (result *QueryResult) IsError() bool { | ||
| 120 | + jResult := gjson.ParseBytes(result.Buf) | ||
| 121 | + for _, arr1 := range jResult.Array() { | ||
| 122 | + for _, item := range arr1.Array() { | ||
| 123 | + if item.IsObject() { | ||
| 124 | + return true | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + return false | ||
| 129 | +} |
pkg/infrastructure/utils/k3cloud/types.go
0 → 100644
| 1 | +package k3cloud | ||
| 2 | + | ||
| 3 | +//postData 请求接口发送的数据结构 | ||
| 4 | +type postData struct { | ||
| 5 | + Format int `json:"format"` | ||
| 6 | + Useragent string `json:"useragent"` | ||
| 7 | + Rid string `json:"rid"` | ||
| 8 | + Parameters interface{} `json:"parameters"` | ||
| 9 | + Timestamp string `json:"timestamp"` | ||
| 10 | + V string `json:"v"` | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +//登录验证请求数据结构 /Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc | ||
| 14 | +type ( | ||
| 15 | + // RequestValidateUser struct { | ||
| 16 | + // AcctID string `json:"acctID"` //账套Id, | ||
| 17 | + // Username string `json:"username"` //密码 | ||
| 18 | + // Password string `json:"password"` //用户登陆名 | ||
| 19 | + // Lcid int `json:"lcid"` //语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307 | ||
| 20 | + // } | ||
| 21 | + | ||
| 22 | + ReponseValidateUser struct { | ||
| 23 | + | ||
| 24 | + /* | ||
| 25 | + 云通行证未绑定Cloud账号 EntryCloudUnBind = -6 | ||
| 26 | + 需要表单处理 DealWithForm = -5 | ||
| 27 | + 登录警告 Wanning = -4 | ||
| 28 | + 密码验证不通过(强制的) PWInvalid_Required = -3 | ||
| 29 | + 密码验证不通过(可选的) PWInvalid_Optional = -2 | ||
| 30 | + 登录失败 Failure = -1 | ||
| 31 | + 用户或密码错误 PWError = 0, | ||
| 32 | + 登录成功 Success = 1 | ||
| 33 | + */ | ||
| 34 | + Message string `json:"Message"` | ||
| 35 | + MessageCode string `json:"MessageCode"` | ||
| 36 | + LoginResultType int `json:"LoginResultType"` | ||
| 37 | + //...其他 | ||
| 38 | + } | ||
| 39 | +) | ||
| 40 | + | ||
| 41 | +//表单数据查询 /K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc | ||
| 42 | +type ( | ||
| 43 | + RequestExecuteBillQuery struct { | ||
| 44 | + FormId string `json:"FormId"` //必录,查询表单元数据唯一标识 | ||
| 45 | + FieldKeys string `json:"FieldKeys"` //必录,待查询表单的字段列表 | ||
| 46 | + Limit int `json:"Limit"` //非必录,分页取数每页允许获取的数据,最大不能超过2000 | ||
| 47 | + StartRow int `json:"StartRow"` //非必录,分页取数开始行索引,从0开始,例如每页10行数据,第2页开始是10,第3页开始是20 | ||
| 48 | + FilterString string `json:"FilterString"` //非必录,过滤条件 | ||
| 49 | + OrderString string `json:"OrderString"` //非必录,排序条件 | ||
| 50 | + TopRowCount int `json:"TopRowCount"` //非必录,返回总行数 | ||
| 51 | + } | ||
| 52 | +) |
pkg/infrastructure/utils/k3cloud/物料元数据.json
0 → 100644
此 diff 太大无法显示。
-
请 注册 或 登录 后发表评论