base_edb_lib.go 18 KB

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