苏州瑞玛APS项目web后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.0 KiB

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"`
}
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
}
const k3url = "http://10.11.12.31/K3Cloud/"
const accID = "61766af04668d8"
const username = "APS2"
const password = "q1w2e3r4"
// 初始化正式环境
func K3configInit() {
k3config := &K3config{}
k3config.CloudUrl = k3url
k3config.AcctID = accID
k3config.Password = password
k3config.Username = username
k3config.LcID = 2052
k3config.FUseOrgId = "1"
k3config.session = util.NewBrowser()
k3config.FUseOrgNo = "C"
k3config.Login()
K3Obj = k3config
}
/**
K3cloud 登录
*/
func (k3config *K3config) Login() {
formParams := util.CreateLoginPostData(k3config.AcctID, k3config.Username, k3config.Password, k3config.LcID, k3config.OrgNumber)
res, _ := k3config.session.PostJson(k3config.CloudUrl+util.LOGIN_API, formParams)
k3Response := response.K3LoginResponseToStruct(res)
if k3Response.LoginResultType == 0 {
panic(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)
if err != nil {
return nil, err
}
return response.K3ResponseToMap(res), nil
}
/**
保存数据
*/
func (K3config *K3config) SaveApi(formId string, saveData request.SaveRequest) (*response.K3ResponseStruct, error) {
formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
res, err := K3config.GetSession().PostJson(K3config.CloudUrl+util.SAVE_API, formParams)
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
}
/**
返回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 ""
}
}