package utils
|
|
|
|
import (
|
|
"fmt"
|
|
util "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/base"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/struct/request"
|
|
"leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/struct/response"
|
|
)
|
|
|
|
type K3config struct {
|
|
CloudUrl string `json:"cloudUrl"` // 地址
|
|
AcctID string `json:"acctID"` //Id
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
LcID int `json:"lcid"`
|
|
OrgNumber string `json:"orgNumber"`
|
|
session *util.Browser
|
|
K3Response response.K3ResponseStruct
|
|
FUseOrgId string `json:"FUseOrgId1"`
|
|
FUseOrgNo string `json:"FUseOrgId1"`
|
|
FUseOrgId2 string `json:"FUseOrgId2"`
|
|
FUseOrgNo2 string `json:"FUseOrgNo2"`
|
|
}
|
|
|
|
var K3Obj *K3config
|
|
|
|
const k3urlTest = "http://101.201.121.115/K3Cloud/"
|
|
const accIDTest = "6197725c05f1f6"
|
|
const usernameTest = "Administrator"
|
|
const passwordTest = "q1w2e3r4!@#$"
|
|
|
|
// 初始化本地测试
|
|
func K3configTestInit() {
|
|
k3config := &K3config{}
|
|
k3config.CloudUrl = k3urlTest
|
|
k3config.AcctID = accIDTest
|
|
k3config.Password = passwordTest
|
|
k3config.Username = usernameTest
|
|
k3config.LcID = 2052
|
|
k3config.FUseOrgId = "1"
|
|
k3config.session = util.NewBrowser()
|
|
k3config.FUseOrgNo = "100"
|
|
k3config.Login()
|
|
K3Obj = k3config
|
|
}
|
|
|
|
//瑞玛测试服UAT
|
|
const k3url = "http://10.11.12.24/K3Cloud/"
|
|
const accID = "61c604a4c1ec4c"
|
|
const username = "aps002"
|
|
const password = "aps1234"
|
|
const OrgId1 = "100729"
|
|
const OrgId2 = "10726"
|
|
const NoId1 = "9999"
|
|
const NoId2 = "9897"
|
|
|
|
//瑞玛测试服
|
|
//const k3url = "http://10.11.12.31/K3Cloud/"
|
|
//const accID = "61766af04668d8"
|
|
//const username = "APS2"
|
|
//const password = "q1w2e3r4"
|
|
//const OrgId1 = "100729"
|
|
//const OrgId2 = "10726"
|
|
//const NoId1 = "9999"
|
|
//const NoId2 = "9897"
|
|
|
|
// 初始化正式环境
|
|
func K3configInit() {
|
|
k3config := &K3config{}
|
|
k3config.CloudUrl = k3url
|
|
k3config.AcctID = accID
|
|
k3config.Password = password
|
|
k3config.Username = username
|
|
k3config.LcID = 2052
|
|
k3config.FUseOrgId = OrgId1
|
|
k3config.session = util.NewBrowser()
|
|
k3config.FUseOrgNo = NoId1
|
|
k3config.FUseOrgId2 = OrgId2
|
|
k3config.FUseOrgNo2 = NoId2
|
|
k3config.Login()
|
|
K3Obj = k3config
|
|
}
|
|
|
|
//瑞玛正式
|
|
//const k3url = "http://10.11.12.24/K3Cloud/"
|
|
//const accID = "6178dbe238ea56"
|
|
//const username = "aps001"
|
|
//const password = "aps202101"
|
|
//const OrgId1 = "100729"
|
|
//const OrgId2 = "100726"
|
|
//const NoId1 = "9999"
|
|
//const NoId2 = "9897"
|
|
|
|
/**
|
|
K3cloud 登录
|
|
*/
|
|
func (k3config *K3config) Login() {
|
|
formParams := util.CreateLoginPostData(k3config.AcctID, k3config.Username, k3config.Password, k3config.LcID, k3config.OrgNumber)
|
|
res, _, _ := k3config.session.LoginPostJson(k3config.CloudUrl+util.LOGIN_API, formParams)
|
|
k3Response := response.K3LoginResponseToStruct(res)
|
|
if k3Response.LoginResultType == 0 {
|
|
fmt.Println(k3Response.Message)
|
|
}
|
|
}
|
|
|
|
/**
|
|
查询数据
|
|
*/
|
|
func (K3config *K3config) SearchApi(formId string, search interface{}) ([][]interface{}, error) {
|
|
//root.Model
|
|
formParams := util.CreateBusinessPostData(formId, util.Struct2Map(search))
|
|
res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.GETBILL_API, formParams)
|
|
K3config.Login()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return response.K3ResponseToMap(res), nil
|
|
}
|
|
|
|
/**
|
|
保存数据
|
|
*/
|
|
func (K3config *K3config) SaveApi(formId string, saveData request.SaveRequest) (*response.K3ResponseStruct, error, string, string) {
|
|
formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
|
|
res, err, req := K3config.GetSession().PostJson(K3config.CloudUrl+util.SAVE_API, formParams)
|
|
K3config.Login()
|
|
if err != nil {
|
|
return nil, err, req, string(res)
|
|
}
|
|
response := response.K3ResponseToStruct(res)
|
|
if !response.Result.ResponseStatus.IsSuccess {
|
|
return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors), req, string(res)
|
|
}
|
|
return &response, nil, req, string(res)
|
|
}
|
|
|
|
//批量保存
|
|
func (K3config *K3config) BatchSaveApi(formId string, saveData request.SaveRequest) (*response.K3ResponseStruct, error) {
|
|
formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
|
|
res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.BATCHSAVE_API, formParams)
|
|
K3config.Login()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
response := response.K3ResponseToStruct(res)
|
|
if !response.Result.ResponseStatus.IsSuccess {
|
|
return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors)
|
|
}
|
|
return &response, nil
|
|
}
|
|
|
|
func (K3config *K3config) BillCloseApi(formId string, opNumber string, saveData request.CloseRequest) (*response.K3ResponseStruct, error) {
|
|
formParams := util.CreateClosePostData(formId, opNumber, util.Struct2Map(saveData))
|
|
res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.BILLCLOSE_API, formParams)
|
|
K3config.Login()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
response := response.K3ResponseToStruct(res)
|
|
if !response.Result.ResponseStatus.IsSuccess {
|
|
return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors)
|
|
}
|
|
fmt.Print(response)
|
|
return &response, nil
|
|
}
|
|
|
|
func (K3config *K3config) DeleteApi(formId string, saveData request.DeleteRequest) (*response.K3ResponseStruct, error) {
|
|
formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
|
|
res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.DELETE_API, formParams)
|
|
K3config.Login()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
response := response.K3ResponseToStruct(res)
|
|
if !response.Result.ResponseStatus.IsSuccess {
|
|
return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors)
|
|
}
|
|
fmt.Print(response)
|
|
return &response, nil
|
|
}
|
|
|
|
/**
|
|
返回session
|
|
*/
|
|
func (k3config *K3config) GetSession() *util.Browser {
|
|
return k3config.session
|
|
}
|
|
|
|
/**
|
|
k3cloud 打印
|
|
*/
|
|
func (k3config *K3config) Print() {
|
|
fmt.Println(k3config.K3Response)
|
|
}
|
|
|
|
/**
|
|
返回接口数据
|
|
*/
|
|
func (k3config *K3config) Get() response.K3ResponseStruct {
|
|
return k3config.K3Response
|
|
}
|
|
|
|
/**
|
|
返回API接口数据
|
|
*/
|
|
func (k3config *K3config) GetResponse() response.K3ResponseStruct {
|
|
return k3config.K3Response
|
|
}
|
|
|
|
var materialgroupMap map[int]string
|
|
|
|
func ClearMaterialgroupMap() {
|
|
materialgroupMap = make(map[int]string)
|
|
}
|
|
|
|
func AppendMaterialgroupMap(key int, info string) {
|
|
materialgroupMap[key] = info
|
|
}
|
|
|
|
func GetMaterialgroupMap(key int) string {
|
|
if _info, ok := materialgroupMap[key]; ok {
|
|
return _info
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func GetAllMaterialgroupMap() map[int]string {
|
|
return materialgroupMap
|
|
}
|
|
|
|
//物料材质
|
|
var materialMap map[string]string
|
|
|
|
func ClearMaterialMap() {
|
|
materialMap = make(map[string]string)
|
|
}
|
|
func AppendMaterialMap(key string, info string) {
|
|
materialMap[key] = info
|
|
}
|
|
|
|
func GetMaterialMap(key string) string {
|
|
if _info, ok := materialMap[key]; ok {
|
|
return _info
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|