base_edb_lib.go 19 KB

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