Browse Source

Merge pull request '金蝶工具类更新' (#71) from feature_jindie into develop

Reviewed-on: #71
feature_msd
徐腾飞 3 years ago
parent
commit
03e63ad659
8 changed files with 3875 additions and 11 deletions
  1. +2
    -5
      main.go
  2. +20
    -2
      utils/k3cloud.go
  3. +7
    -3
      utils/k3cloud/base/curl.go
  4. +49
    -0
      utils/k3cloud/service/cust.go
  5. +1
    -1
      utils/k3cloud/service/voucher.go
  6. +11
    -0
      utils/k3cloud/struct/request/search.go
  7. +6
    -0
      utils/k3cloud/struct/response/responseToStruct.go
  8. +3779
    -0
      utils/k3cloud/table/cust.json

+ 2
- 5
main.go View File

@ -9,8 +9,6 @@ import (
"leit.com/LAPP_CHEERSSON_BACKEND/db"
"leit.com/LAPP_CHEERSSON_BACKEND/infra/logger"
"leit.com/LAPP_CHEERSSON_BACKEND/utils"
utilService "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/service"
_struct "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/struct"
"leit.com/LAPP_CHEERSSON_BACKEND/web/middleware/glog"
"leit.com/LAPP_CHEERSSON_BACKEND/web/routes"
"log"
@ -115,10 +113,9 @@ func imain() {
//加载配置
conf.AppOtherParse()
//加载金蝶云系统
utils.K3configInit()
//utils.K3configInit()
//测试
var root11 _struct.Root
utilService.VoucherInit().GetVoucher(root11)
//utilService.CustInit().Search("FName,FNumber", "", "")
app := iris.New()
//注册中间件
//conf.PreSettring(app)


+ 20
- 2
utils/k3cloud.go View File

@ -41,7 +41,7 @@ K3cloud 登录
*/
func (k3config *K3config) Login() {
formParams := util.CreateLoginPostData(k3config.AcctID, k3config.Username, k3config.Password, k3config.LcID)
res := k3config.session.PostJson(k3config.CloudUrl+util.LOGIN_API, formParams)
res, _ := k3config.session.PostJson(k3config.CloudUrl+util.LOGIN_API, formParams)
k3Response := response.K3LoginResponseToStruct(res)
if k3Response.LoginResultType == 0 {
panic(k3Response.Message)
@ -49,8 +49,26 @@ func (k3config *K3config) Login() {
}
/**
查询数据
*/
func (K3config *K3config) SearchApi(formId string, search interface{}) ([][]string, error) {
//root.Model
formParams := util.CreateBusinessPostData(formId, util.Struct2Map(search))
res, err := K3config.GetSession().PostJson(K3config.CloudUrl+util.GETBILL_API, formParams)
if err != nil {
return nil, err
}
return response.K3ResponseToMap(res), nil
//K3config.K3Response = response.K3ResponseToStruct(res)
//if K3config.K3Response.Result.ResponseStatus.IsSuccess == false {
// return fmt.Errorf(string(res))
//}
//return nil
}
*/
/**
返回session
*/
func (k3config *K3config) GetSession() *util.Browser {
return k3config.session
}


+ 7
- 3
utils/k3cloud/base/curl.go View File

@ -85,21 +85,24 @@ func (self *Browser) Post(requestUrl string, params map[string]string) []byte {
}
//发送PostJson请求
func (self *Browser) PostJson(requestUrl string, params map[string]interface{}) []byte {
func (self *Browser) PostJson(requestUrl string, params map[string]interface{}) ([]byte, error) {
postData := self.jsonParams(params)
fmt.Println(postData)
request, _ := http.NewRequest("POST", requestUrl, strings.NewReader(postData))
request.Header.Set("Content-Type", "application/json")
self.setRequestCookie(request)
response, err := self.client.Do(request)
fmt.Println(err)
if err != nil {
return []byte{}, err
}
defer response.Body.Close()
//保存响应的 cookie
respCks := response.Cookies()
self.cookies = append(self.cookies, respCks...)
data, _ := ioutil.ReadAll(response.Body)
return data
return data, nil
}
//为请求设置 cookie
@ -120,6 +123,7 @@ func (self *Browser) encodeParams(params map[string]string) string {
//参数 json
func (self *Browser) jsonParams(params map[string]interface{}) string {
j, _ := json.Marshal(params)
return string(j)
}

+ 49
- 0
utils/k3cloud/service/cust.go View File

@ -0,0 +1,49 @@
package service
import (
"leit.com/LAPP_CHEERSSON_BACKEND/utils"
utils2 "leit.com/LAPP_CHEERSSON_BACKEND/utils"
request2 "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/struct/request"
)
type CustService struct {
*utils.K3config
FormID string
}
func CustInit() *CustService {
cust := &CustService{
K3config: utils2.K3Obj,
FormID: "CRM_CUST",
}
return cust
}
func (_this *CustService) Search(FieldKeys, FilterString, OrderString string) [][]string {
var data [][]string
request := request2.SearchRequest{
Formid: _this.FormID,
FieldKeys: FieldKeys,
FilterString: FilterString,
OrderString: OrderString,
TopRowCount: 0,
StartRow: 0,
Limit: 1000,
}
for true {
response, err := _this.SearchApi(_this.FormID, request)
if err != nil {
return data
}
for _, v := range response {
data = append(data, v)
}
if len(response) == request.Limit {
request.StartRow = request.StartRow + request.Limit
} else {
break
}
}
return data
}

+ 1
- 1
utils/k3cloud/service/voucher.go View File

@ -25,7 +25,7 @@ func (_this *VoucherService) GetVoucher(root _struct.Root) *VoucherService {
//root.Model
formParams := util.CreateBusinessPostData("GL_VOUCHER", util.Struct2Map(root))
res := _this.GetSession().PostJson(_this.CloudUrl+util.SAVE_API, formParams)
res, _ := _this.GetSession().PostJson(_this.CloudUrl+util.SAVE_API, formParams)
_this.K3Response = response.K3ResponseToStruct(res)
if _this.K3Response.Result.ResponseStatus.IsSuccess == false {
panic(_this.K3Response.Result.ResponseStatus.Errors)


+ 11
- 0
utils/k3cloud/struct/request/search.go View File

@ -0,0 +1,11 @@
package request
type SearchRequest struct {
Formid string `json:"formid"`
FieldKeys string `json:"FieldKeys"`
FilterString string `json:"FilterString"`
OrderString string `json:"OrderString"`
TopRowCount int `json:"TopRowCount"`
StartRow int `json:"StartRow"`
Limit int `json:"Limit"`
}

+ 6
- 0
utils/k3cloud/struct/response/responseToStruct.go View File

@ -60,3 +60,9 @@ func K3ResponseToStruct(data []byte) K3ResponseStruct {
_ = json.Unmarshal(data, &response)
return response
}
func K3ResponseToMap(data []byte) [][]string {
var response [][]string
_ = json.Unmarshal(data, &response)
return response
}

+ 3779
- 0
utils/k3cloud/table/cust.json
File diff suppressed because it is too large
View File


Loading…
Cancel
Save