base_edb_lib.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. package data
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/response"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "io/ioutil"
  10. "net/http"
  11. "strings"
  12. )
  13. // AddEdbData 新增指标数据
  14. func AddEdbData(source int, edbCode, frequency string) (resp *models.BaseResponse, err error) {
  15. param := make(map[string]interface{})
  16. param["EdbCode"] = edbCode
  17. param["Source"] = source
  18. param["Frequency"] = frequency
  19. urlStr := ``
  20. switch source {
  21. case utils.DATA_SOURCE_THS:
  22. urlStr = "ths/add"
  23. case utils.DATA_SOURCE_WIND:
  24. urlStr = "wind/add"
  25. case utils.DATA_SOURCE_PB:
  26. urlStr = "pb/add"
  27. case utils.DATA_SOURCE_PB_FINANCE:
  28. urlStr = "pb_finance/add"
  29. case utils.DATA_SOURCE_MANUAL:
  30. urlStr = "manual/add"
  31. case utils.DATA_SOURCE_LZ:
  32. urlStr = "lz/add"
  33. case utils.DATA_SOURCE_YS:
  34. urlStr = "smm/add"
  35. case utils.DATA_SOURCE_GL:
  36. urlStr = "mysteel/add"
  37. case utils.DATA_SOURCE_ZZ:
  38. urlStr = "zz/add"
  39. case utils.DATA_SOURCE_DL:
  40. urlStr = "dl/add"
  41. case utils.DATA_SOURCE_SH:
  42. urlStr = "sh/add"
  43. case utils.DATA_SOURCE_CFFEX:
  44. urlStr = "cffex/add"
  45. case utils.DATA_SOURCE_SHFE:
  46. urlStr = "shfe/add"
  47. case utils.DATA_SOURCE_GIE:
  48. urlStr = "gie/add"
  49. case utils.DATA_SOURCE_LT:
  50. urlStr = "lt/add"
  51. case utils.DATA_SOURCE_COAL:
  52. urlStr = "coal/add"
  53. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  54. urlStr = "google_travel/add"
  55. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  56. urlStr = "mysteel_chemical/add"
  57. case utils.DATA_SOURCE_EIA_STEO:
  58. urlStr = "eia_steo/add"
  59. case utils.DATA_SOURCE_COM_TRADE:
  60. urlStr = "com_trade/add"
  61. case utils.DATA_SOURCE_SCI:
  62. urlStr = "sci/add"
  63. case utils.DATA_SOURCE_BAIINFO:
  64. urlStr = "baiinfo/add"
  65. case utils.DATA_SOURCE_NATIONAL_STATISTICS:
  66. urlStr = "national_statistics/add"
  67. case utils.DATA_SOURCE_FUBAO:
  68. urlStr = "fubao/add"
  69. case utils.DATA_SOURCE_GFEX:
  70. urlStr = "gz/add"
  71. case utils.DATA_SOURCE_ICPI:
  72. urlStr = "icpi/add"
  73. case utils.DATA_SOURCE_SCI99:
  74. urlStr = "sci99/add"
  75. case utils.DATA_SOURCE_SCI_HQ:
  76. urlStr = "sci_hq/add"
  77. default:
  78. edbSource := data_manage.EdbSourceIdMap[source]
  79. if edbSource != nil {
  80. urlStr = edbSource.EdbAddMethod
  81. }
  82. }
  83. if urlStr == "" {
  84. err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
  85. return
  86. }
  87. resp, err = postRefreshEdbData(param, urlStr)
  88. return
  89. }
  90. // AddEdbData 新增指标数据
  91. func AddEdbDataWindWsd(source int, stockCode, edbCode string) (resp *models.BaseResponse, err error) {
  92. param := make(map[string]interface{})
  93. param["EdbCode"] = edbCode
  94. param["StockCode"] = stockCode
  95. param["Source"] = source
  96. urlStr := `wind/wsd/add`
  97. if urlStr == "" {
  98. err = fmt.Errorf("未实现该指标的刷新接口,请联系管理员")
  99. return
  100. }
  101. resp, err = postRefreshEdbData(param, urlStr)
  102. return
  103. }
  104. // AddEdbDataThsDs 新增指标数据
  105. func AddEdbDataThsDs(source int, stockCode, edbCode, extraPars string) (resp *models.BaseResponse, err error) {
  106. param := make(map[string]interface{})
  107. param["EdbCode"] = edbCode
  108. param["StockCode"] = stockCode
  109. param["Source"] = source
  110. param["ExtraPars"] = extraPars
  111. urlStr := `ths/ds/add`
  112. resp, err = postRefreshEdbData(param, urlStr)
  113. return
  114. }
  115. type AddPredictEdbDataResponse struct {
  116. Ret int
  117. Msg string
  118. ErrMsg string
  119. ErrCode string
  120. Data data_manage.AddEdbInfoResp
  121. Success bool `description:"true 执行成功,false 执行失败"`
  122. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  123. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  124. }
  125. // EdbCalculateSaveMultiResponse 批量计算返回值
  126. type EdbCalculateSaveMultiResponse struct {
  127. Ret int
  128. Msg string
  129. ErrMsg string
  130. ErrCode string
  131. Data data_manage.BatchEdbInfoCalculateBatchSaveResp
  132. Success bool `description:"true 执行成功,false 执行失败"`
  133. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  134. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  135. }
  136. // SaveBasePredictEdbData 新增/编辑预测指标运算
  137. func SaveBasePredictEdbData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  138. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict/save", lang)
  139. err = json.Unmarshal(resultByte, &resp)
  140. if err != nil {
  141. return
  142. }
  143. return
  144. }
  145. type PredictRuleCalculateByNineRespResponse struct {
  146. Ret int
  147. Msg string
  148. ErrMsg string
  149. ErrCode string
  150. Data response.PredictRuleCalculateByNineResp
  151. Success bool `description:"true 执行成功,false 执行失败"`
  152. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  153. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  154. }
  155. // PredictCalculateByNinePreview 预测指标动态环差演算
  156. func PredictCalculateByNinePreview(RuleConfigReqStr, lang string) (resp *PredictRuleCalculateByNineRespResponse, err error) {
  157. _, resultByte, err := postAddEdbData(RuleConfigReqStr, "predict/calculate_by_nine/preview", lang)
  158. err = json.Unmarshal(resultByte, &resp)
  159. if err != nil {
  160. return
  161. }
  162. return
  163. }
  164. // SavePredictEdbData 新增/编辑预测指标运算
  165. func SavePredictEdbData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  166. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict_calculate/save", lang)
  167. err = json.Unmarshal(resultByte, &resp)
  168. if err != nil {
  169. return
  170. }
  171. return
  172. }
  173. // BatchSavePredictEdbData 新增/编辑 预测指标运算(同比、同差)
  174. func BatchSavePredictEdbData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  175. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict_calculate/batch/save", lang)
  176. if err != nil {
  177. return
  178. }
  179. err = json.Unmarshal(resultByte, &resp)
  180. if err != nil {
  181. return
  182. }
  183. return
  184. }
  185. // RefreshEdbData 刷新指标数据
  186. func RefreshEdbData(edbInfoId, source, subSource int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  187. param := make(map[string]interface{})
  188. param["EdbCode"] = edbCode
  189. param["EdbInfoId"] = edbInfoId
  190. param["StartDate"] = startDate
  191. param["Source"] = source
  192. urlStr := ``
  193. switch source {
  194. case utils.DATA_SOURCE_THS:
  195. switch subSource {
  196. case utils.DATA_SUB_SOURCE_DATE:
  197. urlStr = "ths/ds/refresh"
  198. case utils.DATA_SUB_SOURCE_HIGH_FREQUENCY:
  199. urlStr = "ths/hf/edb/refresh"
  200. default:
  201. urlStr = "ths/refresh"
  202. }
  203. case utils.DATA_SOURCE_WIND:
  204. if subSource == 0 {
  205. urlStr = "wind/refresh"
  206. } else {
  207. urlStr = "wind/wsd/refresh"
  208. }
  209. case utils.DATA_SOURCE_PB:
  210. urlStr = "pb/refresh"
  211. case utils.DATA_SOURCE_PB_FINANCE:
  212. urlStr = "pb_finance/refresh"
  213. case utils.DATA_SOURCE_MANUAL:
  214. urlStr = "manual/refresh"
  215. case utils.DATA_SOURCE_LZ:
  216. urlStr = "lz/refresh"
  217. case utils.DATA_SOURCE_YS:
  218. urlStr = "smm/refresh"
  219. case utils.DATA_SOURCE_GL:
  220. urlStr = "mysteel/refresh"
  221. case utils.DATA_SOURCE_ZZ:
  222. urlStr = "zz/refresh"
  223. case utils.DATA_SOURCE_DL:
  224. urlStr = "dl/refresh"
  225. case utils.DATA_SOURCE_SH:
  226. urlStr = "sh/refresh"
  227. case utils.DATA_SOURCE_CFFEX:
  228. urlStr = "cffex/refresh"
  229. case utils.DATA_SOURCE_SHFE:
  230. urlStr = "shfe/refresh"
  231. case utils.DATA_SOURCE_GIE:
  232. urlStr = "gie/refresh"
  233. case utils.DATA_SOURCE_LT:
  234. urlStr = "lt/refresh"
  235. case utils.DATA_SOURCE_COAL:
  236. urlStr = "coal/refresh"
  237. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  238. urlStr = "google_travel/refresh"
  239. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  240. urlStr = "mysteel_chemical/refresh"
  241. case utils.DATA_SOURCE_EIA_STEO:
  242. urlStr = "eia_steo/refresh"
  243. case utils.DATA_SOURCE_PREDICT:
  244. urlStr = "predict/refresh"
  245. case utils.DATA_SOURCE_COM_TRADE:
  246. urlStr = "com_trade/refresh"
  247. case utils.DATA_SOURCE_SCI:
  248. urlStr = "sci/refresh"
  249. case utils.DATA_SOURCE_BAIINFO:
  250. urlStr = "baiinfo/refresh"
  251. case utils.DATA_SOURCE_STOCK_PLANT:
  252. urlStr = "stock_plant/refresh"
  253. case utils.DATA_SOURCE_NATIONAL_STATISTICS:
  254. urlStr = "national_statistics/refresh"
  255. case utils.DATA_SOURCE_FUBAO:
  256. urlStr = "fubao/refresh"
  257. case utils.DATA_SOURCE_GFEX:
  258. urlStr = "gz/refresh"
  259. case utils.DATA_SOURCE_ICPI:
  260. urlStr = "icpi/refresh"
  261. case utils.DATA_SOURCE_SCI99:
  262. urlStr = "sci99/refresh"
  263. case utils.DATA_SOURCE_SCI_HQ:
  264. urlStr = "sci_hq/refresh"
  265. default:
  266. edbSource := data_manage.EdbSourceIdMap[source]
  267. if edbSource != nil {
  268. urlStr = edbSource.EdbRefreshMethod
  269. }
  270. }
  271. if urlStr == "" {
  272. err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
  273. return
  274. }
  275. resp, err = postRefreshEdbData(param, urlStr)
  276. return
  277. }
  278. // RefreshEdbCalculateData 刷新普通计算指标数据请求
  279. func RefreshEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  280. param := make(map[string]interface{})
  281. param["EdbCode"] = edbCode
  282. param["EdbInfoId"] = edbInfoId
  283. param["StartDate"] = startDate
  284. resp, err = postRefreshEdbData(param, "calculate/refresh")
  285. return
  286. }
  287. // RefreshPredictEdbCalculateData 刷新 预测计算指标 数据请求
  288. func RefreshPredictEdbCalculateData(edbInfoId int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
  289. param := make(map[string]interface{})
  290. param["EdbCode"] = edbCode
  291. param["EdbInfoId"] = edbInfoId
  292. param["StartDate"] = startDate
  293. resp, err = postRefreshEdbData(param, "predict_calculate/refresh")
  294. return
  295. }
  296. // AddEdbCalculateData 新增 累计值转月-同比值-同差等计算新增
  297. func AddEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  298. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/add", lang)
  299. err = json.Unmarshal(resultByte, &resp)
  300. if err != nil {
  301. return
  302. }
  303. return
  304. }
  305. // EditEdbCalculateData 编辑 累计值转月-同比值-同差等计算新增
  306. func EditEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  307. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/edit", lang)
  308. err = json.Unmarshal(resultByte, &resp)
  309. if err != nil {
  310. return
  311. }
  312. return
  313. }
  314. // BatchSaveEdbCalculateData 新增 累计值转月-同比值-同差等计算新增
  315. func BatchSaveEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  316. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/save", lang)
  317. err = json.Unmarshal(resultByte, &resp)
  318. if err != nil {
  319. return
  320. }
  321. return
  322. }
  323. // BatchEditEdbCalculateData 编辑 累计值转月-同比值-同差等计算新增
  324. func BatchEditEdbCalculateData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  325. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/edit", lang)
  326. err = json.Unmarshal(resultByte, &resp)
  327. if err != nil {
  328. return
  329. }
  330. return
  331. }
  332. // BatchSaveEdbCalculateMultiData 批量新增 累计值转月-同比值-同差等计算新增
  333. func BatchSaveEdbCalculateMultiData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *EdbCalculateSaveMultiResponse, err error) {
  334. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/save/multi", lang)
  335. err = json.Unmarshal(resultByte, &resp)
  336. if err != nil {
  337. return
  338. }
  339. return
  340. }
  341. // BatchEditEdbCalculateMultiData 批量编辑 累计值转月-同比值-同差等计算新增
  342. func BatchEditEdbCalculateMultiData(edbInfoCalculateBatchSaveReqStr, lang string) (resp *EdbCalculateSaveMultiResponse, err error) {
  343. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/batch/edit/multi", lang)
  344. err = json.Unmarshal(resultByte, &resp)
  345. if err != nil {
  346. return
  347. }
  348. return
  349. }
  350. //// EditEdbCalculateData 修改计算指标数据请求
  351. //func EditEdbCalculateData(edbInfoCalculateBatchSaveReqStr string) (resp *models.BaseResponse, err error) {
  352. // resp, _, err = postAddEdbData(edbInfoCalculateBatchSaveReqStr, "batch/save")
  353. // return
  354. //}
  355. // ExecPythonCode 执行python代码
  356. func ExecPythonCode(pythonCode string) (resp *models.BaseResponse, err error) {
  357. param := make(map[string]interface{})
  358. param["PythonCode"] = pythonCode
  359. urlStr := `/python/exec`
  360. resp, err = postRefreshEdbData(param, urlStr)
  361. return
  362. }
  363. // AddPythonEdbData 新增python指标
  364. func AddPythonEdbData(param, lang string) (resp *models.BaseResponse, err error) {
  365. urlStr := ``
  366. urlStr = "python/add"
  367. resp, _, err = postAddEdbData(param, urlStr, lang)
  368. return
  369. }
  370. // EditPythonEdbData 编辑python指标
  371. func EditPythonEdbData(param, lang string) (resp *models.BaseResponse, err error) {
  372. urlStr := ``
  373. urlStr = "python/edit"
  374. resp, _, err = postAddEdbData(param, urlStr, lang)
  375. return
  376. }
  377. // SaveAdjustEdbInfo 保存数据调整指标
  378. func SaveAdjustEdbInfo(param, lang string) (resp *models.BaseResponse, err error) {
  379. urlStr := ``
  380. urlStr = "calculate/adjust/save"
  381. resp, _, err = postAddEdbData(param, urlStr, lang)
  382. return
  383. }
  384. // ResetCustomAnalysisData 重置自定义表格的数据
  385. func ResetCustomAnalysisData(reqStr, lang string) (resp *AddPredictEdbDataResponse, err error) {
  386. _, resultByte, err := postAddEdbData(reqStr, "calculate/custom_analysis/reset", lang)
  387. err = json.Unmarshal(resultByte, &resp)
  388. if err != nil {
  389. return
  390. }
  391. return
  392. }
  393. // CalculateComputeCorrelationResp 拟合残差计算相关性的值返回
  394. type CalculateComputeCorrelationResp struct {
  395. Ret int
  396. Msg string
  397. ErrMsg string
  398. ErrCode string
  399. Data string
  400. Success bool `description:"true 执行成功,false 执行失败"`
  401. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  402. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  403. }
  404. // CalculateComputeCorrelation 拟合残差计算相关性的值
  405. func CalculateComputeCorrelation(edbInfoCalculateBatchSaveReqStr, lang string) (resp *CalculateComputeCorrelationResp, err error) {
  406. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "calculate/compute_correlation", lang)
  407. err = json.Unmarshal(resultByte, &resp)
  408. if err != nil {
  409. return
  410. }
  411. return
  412. }
  413. // PredictCalculateComputeCorrelation 拟合残差计算相关性的值(预测指标)
  414. func PredictCalculateComputeCorrelation(edbInfoCalculateBatchSaveReqStr, lang string) (resp *CalculateComputeCorrelationResp, err error) {
  415. _, resultByte, err := postAddEdbData(edbInfoCalculateBatchSaveReqStr, "predict_calculate/compute_correlation", lang)
  416. err = json.Unmarshal(resultByte, &resp)
  417. if err != nil {
  418. return
  419. }
  420. return
  421. }
  422. // BaseCalculateResp 拟合残差计算相关性的值返回
  423. type BaseCalculateResp struct {
  424. Ret int
  425. Msg string
  426. ErrMsg string
  427. ErrCode string
  428. Data BaseCalculateDataResp
  429. Success bool `description:"true 执行成功,false 执行失败"`
  430. IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
  431. IsAddLog bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
  432. }
  433. // BaseCalculateDataResp
  434. // @Description: 基础计算的返回结果
  435. type BaseCalculateDataResp struct {
  436. DataMap map[string]float64
  437. DateList []string
  438. }
  439. // BaseCalculate 基础计算
  440. func BaseCalculate(param, lang string) (resp *BaseCalculateResp, err error) {
  441. urlStr := "calculate/base"
  442. _, resultByte, err := postAddEdbData(param, urlStr, lang)
  443. err = json.Unmarshal(resultByte, &resp)
  444. if err != nil {
  445. return
  446. }
  447. return
  448. }
  449. // AddBaseEdbInfo 新增基础指标
  450. func AddBaseEdbInfo(addBaseEdbInfoReqStr string, source, subSource int, lang string) (resp *AddPredictEdbDataResponse, err error) {
  451. urlStr := ``
  452. switch source {
  453. case utils.DATA_SOURCE_BUSINESS:
  454. urlStr = "business_index/add"
  455. case utils.DATA_SOURCE_THS:
  456. if subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY {
  457. urlStr = "ths/hf/edb/add"
  458. }
  459. default:
  460. edbSource := data_manage.EdbSourceIdMap[source]
  461. if edbSource != nil {
  462. urlStr = edbSource.EdbRefreshMethod
  463. }
  464. }
  465. if urlStr == "" {
  466. err = fmt.Errorf(fmt.Sprint("source:", source, ";未实现该指标的刷新接口,请联系管理员"))
  467. return
  468. }
  469. _, resultByte, err := postAddEdbData(addBaseEdbInfoReqStr, urlStr, lang)
  470. if err != nil {
  471. return
  472. }
  473. err = json.Unmarshal(resultByte, &resp)
  474. return
  475. }
  476. // postRefreshEdbData 刷新指标数据
  477. func postRefreshEdbData(param map[string]interface{}, urlStr string) (resp *models.BaseResponse, err error) {
  478. postUrl := utils.EDB_LIB_URL + urlStr
  479. postData, err := json.Marshal(param)
  480. if err != nil {
  481. return
  482. }
  483. result, err := HttpPost(postUrl, string(postData), utils.ZhLangVersion, "application/json")
  484. if err != nil {
  485. return
  486. }
  487. utils.FileLog.Info("postRefreshEdbData:" + postUrl + ";" + string(postData) + ";result:" + string(result))
  488. err = json.Unmarshal(result, &resp)
  489. if err != nil {
  490. return
  491. }
  492. return resp, nil
  493. }
  494. // postAddEdbData 新增指标数据
  495. func postAddEdbData(paramStr string, urlStr, lang string) (resp *models.BaseResponse, result []byte, err error) {
  496. postUrl := utils.EDB_LIB_URL + urlStr
  497. result, err = HttpPost(postUrl, paramStr, lang, "application/json")
  498. if err != nil {
  499. return
  500. }
  501. err = json.Unmarshal(result, &resp)
  502. if err != nil {
  503. return
  504. }
  505. return
  506. }
  507. func HttpPost(url, postData, lang string, params ...string) ([]byte, error) {
  508. body := ioutil.NopCloser(strings.NewReader(postData))
  509. client := &http.Client{}
  510. req, err := http.NewRequest("POST", url, body)
  511. if err != nil {
  512. return nil, err
  513. }
  514. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  515. if len(params) > 0 && params[0] != "" {
  516. contentType = params[0]
  517. }
  518. req.Header.Set("Content-Type", contentType)
  519. req.Header.Set("Lang", lang)
  520. req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
  521. resp, err := client.Do(req)
  522. if err != nil {
  523. return nil, err
  524. }
  525. defer resp.Body.Close()
  526. b, err := ioutil.ReadAll(resp.Body)
  527. utils.FileLog.Debug("HttpPost:" + string(b))
  528. return b, err
  529. }
  530. // BaseStepCalculate 基础运算-多步骤
  531. func BaseStepCalculate(param, lang string) (resp *BaseCalculateResp, err error) {
  532. urlStr := "calculate/base/step_calculate"
  533. _, resultByte, err := postAddEdbData(param, urlStr, lang)
  534. err = json.Unmarshal(resultByte, &resp)
  535. if err != nil {
  536. return
  537. }
  538. return
  539. }