苏州瑞玛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.

258 lines
6.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package utils
  2. import (
  3. "fmt"
  4. util "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/base"
  5. "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/struct/request"
  6. "leit.com/LAPP_CHEERSSON_BACKEND/utils/k3cloud/struct/response"
  7. )
  8. type K3config struct {
  9. CloudUrl string `json:"cloudUrl"` // 地址
  10. AcctID string `json:"acctID"` //Id
  11. Username string `json:"username"`
  12. Password string `json:"password"`
  13. LcID int `json:"lcid"`
  14. OrgNumber string `json:"orgNumber"`
  15. session *util.Browser
  16. K3Response response.K3ResponseStruct
  17. FUseOrgId string `json:"FUseOrgId1"`
  18. FUseOrgNo string `json:"FUseOrgId1"`
  19. FUseOrgId2 string `json:"FUseOrgId2"`
  20. FUseOrgNo2 string `json:"FUseOrgNo2"`
  21. }
  22. var K3Obj *K3config
  23. const k3urlTest = "http://101.201.121.115/K3Cloud/"
  24. const accIDTest = "6197725c05f1f6"
  25. const usernameTest = "Administrator"
  26. const passwordTest = "q1w2e3r4!@#$"
  27. // 初始化本地测试
  28. func K3configTestInit() {
  29. k3config := &K3config{}
  30. k3config.CloudUrl = k3urlTest
  31. k3config.AcctID = accIDTest
  32. k3config.Password = passwordTest
  33. k3config.Username = usernameTest
  34. k3config.LcID = 2052
  35. k3config.FUseOrgId = "1"
  36. k3config.session = util.NewBrowser()
  37. k3config.FUseOrgNo = "100"
  38. k3config.Login()
  39. K3Obj = k3config
  40. }
  41. //UAT新
  42. const k3url = "http://10.11.12.24/K3Cloud/"
  43. const accID = "61cff33d2cf273"
  44. const username = "aps001"
  45. const password = "aps202101"
  46. const OrgId1 = "100729"
  47. const OrgId2 = "100726"
  48. const NoId1 = "9999"
  49. const NoId2 = "9897"
  50. //瑞玛测试服UAT
  51. //const k3url = "http://10.11.12.24/K3Cloud/"
  52. //const accID = "61c604a4c1ec4c"
  53. //const username = "aps002"
  54. //const password = "aps1234"
  55. //const OrgId1 = "100729"
  56. //const OrgId2 = "10726"
  57. //const NoId1 = "9999"
  58. //const NoId2 = "9897"
  59. //瑞玛测试服
  60. //const k3url = "http://10.11.12.31/K3Cloud/"
  61. //const accID = "61766af04668d8"
  62. //const username = "APS2"
  63. //const password = "q1w2e3r4"
  64. //const OrgId1 = "100729"
  65. //const OrgId2 = "10726"
  66. //const NoId1 = "9999"
  67. //const NoId2 = "9897"
  68. // 初始化正式环境
  69. func K3configInit() {
  70. k3config := &K3config{}
  71. k3config.CloudUrl = k3url
  72. k3config.AcctID = accID
  73. k3config.Password = password
  74. k3config.Username = username
  75. k3config.LcID = 2052
  76. k3config.FUseOrgId = OrgId1
  77. k3config.session = util.NewBrowser()
  78. k3config.FUseOrgNo = NoId1
  79. k3config.FUseOrgId2 = OrgId2
  80. k3config.FUseOrgNo2 = NoId2
  81. k3config.Login()
  82. K3Obj = k3config
  83. }
  84. //瑞玛正式
  85. //const k3url = "http://10.11.12.24/K3Cloud/"
  86. //const accID = "6178dbe238ea56"
  87. //const username = "aps001"
  88. //const password = "aps202101"
  89. //const OrgId1 = "100729"
  90. //const OrgId2 = "100726"
  91. //const NoId1 = "9999"
  92. //const NoId2 = "9897"
  93. /**
  94. K3cloud 登录
  95. */
  96. func (k3config *K3config) Login() {
  97. formParams := util.CreateLoginPostData(k3config.AcctID, k3config.Username, k3config.Password, k3config.LcID, k3config.OrgNumber)
  98. res, _, _ := k3config.session.LoginPostJson(k3config.CloudUrl+util.LOGIN_API, formParams)
  99. k3Response := response.K3LoginResponseToStruct(res)
  100. if k3Response.LoginResultType == 0 {
  101. fmt.Println(k3Response.Message)
  102. }
  103. }
  104. /**
  105. 查询数据
  106. */
  107. func (K3config *K3config) SearchApi(formId string, search interface{}) ([][]interface{}, error) {
  108. //root.Model
  109. formParams := util.CreateBusinessPostData(formId, util.Struct2Map(search))
  110. res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.GETBILL_API, formParams)
  111. K3config.Login()
  112. if err != nil {
  113. return nil, err
  114. }
  115. return response.K3ResponseToMap(res), nil
  116. }
  117. /**
  118. 保存数据
  119. */
  120. func (K3config *K3config) SaveApi(formId string, saveData request.SaveRequest) (*response.K3ResponseStruct, error, string, string) {
  121. formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
  122. res, err, req := K3config.GetSession().PostJson(K3config.CloudUrl+util.SAVE_API, formParams)
  123. K3config.Login()
  124. if err != nil {
  125. return nil, err, req, string(res)
  126. }
  127. response := response.K3ResponseToStruct(res)
  128. if !response.Result.ResponseStatus.IsSuccess {
  129. return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors), req, string(res)
  130. }
  131. return &response, nil, req, string(res)
  132. }
  133. //批量保存
  134. func (K3config *K3config) BatchSaveApi(formId string, saveData request.SaveRequest) (*response.K3ResponseStruct, error) {
  135. formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
  136. res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.BATCHSAVE_API, formParams)
  137. K3config.Login()
  138. if err != nil {
  139. return nil, err
  140. }
  141. response := response.K3ResponseToStruct(res)
  142. if !response.Result.ResponseStatus.IsSuccess {
  143. return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors)
  144. }
  145. return &response, nil
  146. }
  147. func (K3config *K3config) BillCloseApi(formId string, opNumber string, saveData request.CloseRequest) (*response.K3ResponseStruct, error) {
  148. formParams := util.CreateClosePostData(formId, opNumber, util.Struct2Map(saveData))
  149. res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.BILLCLOSE_API, formParams)
  150. K3config.Login()
  151. if err != nil {
  152. return nil, err
  153. }
  154. response := response.K3ResponseToStruct(res)
  155. if !response.Result.ResponseStatus.IsSuccess {
  156. return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors)
  157. }
  158. fmt.Print(response)
  159. return &response, nil
  160. }
  161. func (K3config *K3config) DeleteApi(formId string, saveData request.DeleteRequest) (*response.K3ResponseStruct, error) {
  162. formParams := util.CreateBusinessPostData(formId, util.Struct2Map(saveData))
  163. res, err, _ := K3config.GetSession().PostJson(K3config.CloudUrl+util.DELETE_API, formParams)
  164. K3config.Login()
  165. if err != nil {
  166. return nil, err
  167. }
  168. response := response.K3ResponseToStruct(res)
  169. if !response.Result.ResponseStatus.IsSuccess {
  170. return nil, fmt.Errorf("%s", response.Result.ResponseStatus.Errors)
  171. }
  172. fmt.Print(response)
  173. return &response, nil
  174. }
  175. /**
  176. 返回session
  177. */
  178. func (k3config *K3config) GetSession() *util.Browser {
  179. return k3config.session
  180. }
  181. /**
  182. k3cloud 打印
  183. */
  184. func (k3config *K3config) Print() {
  185. fmt.Println(k3config.K3Response)
  186. }
  187. /**
  188. 返回接口数据
  189. */
  190. func (k3config *K3config) Get() response.K3ResponseStruct {
  191. return k3config.K3Response
  192. }
  193. /**
  194. 返回API接口数据
  195. */
  196. func (k3config *K3config) GetResponse() response.K3ResponseStruct {
  197. return k3config.K3Response
  198. }
  199. var materialgroupMap map[int]string
  200. func ClearMaterialgroupMap() {
  201. materialgroupMap = make(map[int]string)
  202. }
  203. func AppendMaterialgroupMap(key int, info string) {
  204. materialgroupMap[key] = info
  205. }
  206. func GetMaterialgroupMap(key int) string {
  207. if _info, ok := materialgroupMap[key]; ok {
  208. return _info
  209. } else {
  210. return ""
  211. }
  212. }
  213. func GetAllMaterialgroupMap() map[int]string {
  214. return materialgroupMap
  215. }
  216. //物料材质
  217. var materialMap map[string]string
  218. func ClearMaterialMap() {
  219. materialMap = make(map[string]string)
  220. }
  221. func AppendMaterialMap(key string, info string) {
  222. materialMap[key] = info
  223. }
  224. func GetMaterialMap(key string) string {
  225. if _info, ok := materialMap[key]; ok {
  226. return _info
  227. } else {
  228. return ""
  229. }
  230. }