base_edb_lib.go 19 KB

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