data_source.go 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. package data_source
  2. import (
  3. "eta/eta_task/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. // SearchDataSource 数据源ES搜索
  11. type SearchDataSource struct {
  12. PrimaryId int `description:"主键ID"`
  13. IndexCode string `description:"指标编码"`
  14. IndexName string `description:"指标名称"`
  15. ClassifyId int `description:"分类ID"`
  16. Unit string `description:"单位"`
  17. Frequency string `description:"频度"`
  18. StartDate string `description:"开始日期"`
  19. EndDate string `description:"结束日期"`
  20. LatestValue float64 `description:"最新值"`
  21. Source int `description:"来源"`
  22. SourceName string `description:"数据源名称"`
  23. SubSource int `description:"子来源"`
  24. IsDeleted int `description:"是否已删除:0-正常;1-已删除"`
  25. CreateTime string `description:"创建时间"`
  26. ModifyTime string `description:"修改时间"`
  27. }
  28. // SearchDataSourceItem 数据源ES搜索
  29. type SearchDataSourceItem struct {
  30. SearchDataSource
  31. SearchText string `description:"搜索结果(含高亮)"`
  32. }
  33. // ToMap 为了方便前端那边的修改,这里兼容一下部分Key的变动,不然改动量很大
  34. func (s *SearchDataSourceItem) ToMap(primaryIdKey, indexNameKey, classifyIdKey string) map[string]interface{} {
  35. data := make(map[string]interface{})
  36. if primaryIdKey != "" {
  37. data[primaryIdKey] = s.PrimaryId
  38. } else {
  39. data["PrimaryId"] = s.PrimaryId
  40. }
  41. if indexNameKey != "" {
  42. data[indexNameKey] = s.IndexName
  43. } else {
  44. data["IndexName"] = s.IndexName
  45. }
  46. if classifyIdKey != "" {
  47. data[classifyIdKey] = s.ClassifyId
  48. } else {
  49. data["ClassifyId"] = s.ClassifyId
  50. }
  51. data["IndexCode"] = s.IndexCode
  52. data["Unit"] = s.Unit
  53. data["Frequency"] = s.Frequency
  54. data["StartDate"] = s.StartDate
  55. data["EndDate"] = s.EndDate
  56. data["LatestValue"] = s.LatestValue
  57. data["Source"] = s.Source
  58. data["SourceName"] = s.SourceName
  59. data["IsDeleted"] = s.IsDeleted
  60. data["CreateTime"] = s.CreateTime
  61. data["ModifyTime"] = s.ModifyTime
  62. data["SearchText"] = s.SearchText
  63. return data
  64. }
  65. // SearchDataSourceResp 数据源ES-分页搜索响应
  66. type SearchDataSourceResp struct {
  67. Paging *paging.PagingItem
  68. List []map[string]interface{}
  69. }
  70. // SearchEsCols 数据源ES搜索字段
  71. type SearchEsCols struct {
  72. PrimaryId string
  73. IndexCode string
  74. IndexName string
  75. ClassifyId string
  76. Unit string
  77. Frequency string
  78. StartDate string
  79. EndDate string
  80. LatestValue string
  81. CreateTime string
  82. ModifyTime string
  83. }
  84. // EsBaseFromIndex 数据源ES统一实现的接口
  85. type EsBaseFromIndex interface {
  86. EsCols() SearchEsCols
  87. SourceInfo() (int, int, string)
  88. }
  89. // GetEsBaseFromIndexByTableName 根据表名获取对应数据源
  90. func GetEsBaseFromIndexByTableName(tableName string) EsBaseFromIndex {
  91. switch tableName {
  92. case "base_from_rzd_index":
  93. return &BaseFromRzdIndex{}
  94. case "base_from_hisugar_index":
  95. return &BaseFromHisugarIndex{}
  96. case "base_from_ly_index":
  97. return &BaseFromLyIndex{}
  98. case "base_from_sci_hq_index":
  99. return &BaseFromSciHqIndex{}
  100. case "base_from_oilchem_index":
  101. return &BaseFromOilchemIndex{}
  102. case "base_from_ths_hf_index":
  103. return &BaseFromThsHfIndex{}
  104. case "base_from_ccf_index":
  105. return &BaseFromCcfIndex{}
  106. case "base_from_usda_fas_index":
  107. return &BaseFromUsdaFasIndex{}
  108. case "base_from_mysteel_chemical_index":
  109. return &BaseFromMysteelChemicalIndex{}
  110. case "base_from_smm_index":
  111. return &BaseFromSmmIndex{}
  112. case "base_from_baiinfo_index":
  113. return &BaseFromBaiinfoIndex{}
  114. case "base_from_sci_index":
  115. return &BaseFromSciIndex{}
  116. case "base_from_coalmine_mapping":
  117. return &BaseFromCoalmineMapping{}
  118. case "base_from_eia_steo_index":
  119. return &BaseFromEiaSteoIndex{}
  120. case "base_from_icpi_index":
  121. return &BaseFromIcpiIndex{}
  122. case "base_from_yongyi_index":
  123. return &BaseFromYongyiIndex{}
  124. case "base_from_fenwei_index":
  125. return &BaseFromFenweiIndex{}
  126. case "base_from_sci99_index":
  127. return &BaseFromSci99Index{}
  128. case "mb_index_main_info":
  129. return &BaseFromGlIndex{}
  130. case "edbinfo":
  131. return &BaseFromManualEdb{}
  132. case "base_from_business_index":
  133. return &BaseFromBusinessIndex{}
  134. case "base_from_bloomberg_index":
  135. return &BaseFromBloombergIndex{}
  136. case "base_from_mtjh_mapping":
  137. return &BaseFromMtjhMapping{}
  138. }
  139. return nil
  140. }
  141. // BaseFromRzdIndex 睿咨得
  142. type BaseFromRzdIndex struct {
  143. BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id);pk"`
  144. BaseFromRzdClassifyId int `description:"分类ID"`
  145. IndexCode string `description:"指标编码"`
  146. IndexName string `description:"指标名称"`
  147. Unit string `description:"单位"`
  148. Frequency string `description:"频度"`
  149. StartDate time.Time `description:"开始日期"`
  150. EndDate time.Time `description:"结束日期"`
  151. LatestValue float64 `description:"最新值"`
  152. CreateTime time.Time `description:"创建时间"`
  153. ModifyTime time.Time `description:"更新时间"`
  154. }
  155. func (m *BaseFromRzdIndex) SourceInfo() (int, int, string) {
  156. return utils.DATA_SOURCE_RZD, 0, "睿咨得"
  157. }
  158. func (m *BaseFromRzdIndex) EsCols() SearchEsCols {
  159. return SearchEsCols{
  160. PrimaryId: "base_from_rzd_index_id",
  161. IndexCode: "index_code",
  162. IndexName: "index_name",
  163. ClassifyId: "base_from_rzd_classify_id",
  164. Unit: "unit",
  165. Frequency: "frequency",
  166. StartDate: "start_date",
  167. EndDate: "end_date",
  168. LatestValue: "latest_value",
  169. CreateTime: "create_time",
  170. ModifyTime: "modify_time",
  171. }
  172. }
  173. func (m *BaseFromRzdIndex) Format2SearchDataSource(origin *BaseFromRzdIndex) (item *SearchDataSource) {
  174. if origin == nil {
  175. return
  176. }
  177. source, subSource, sourceName := m.SourceInfo()
  178. item = new(SearchDataSource)
  179. item.PrimaryId = origin.BaseFromRzdIndexId
  180. item.IndexCode = origin.IndexCode
  181. item.IndexName = origin.IndexName
  182. item.ClassifyId = origin.BaseFromRzdClassifyId
  183. item.Unit = origin.Unit
  184. item.Frequency = origin.Frequency
  185. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  186. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  187. item.LatestValue = origin.LatestValue
  188. item.Source = source
  189. item.SubSource = subSource
  190. item.SourceName = sourceName
  191. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  192. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  193. return
  194. }
  195. func (m *BaseFromRzdIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromRzdIndex, err error) {
  196. o := orm.NewOrmUsingDB("data")
  197. fields := strings.Join(fieldArr, ",")
  198. if len(fieldArr) == 0 {
  199. fields = `*`
  200. }
  201. order := `ORDER BY create_time DESC`
  202. if orderRule != "" {
  203. order = ` ORDER BY ` + orderRule
  204. }
  205. sql := fmt.Sprintf(`SELECT %s FROM base_from_rzd_index WHERE 1=1 %s %s`, fields, condition, order)
  206. _, err = o.Raw(sql, pars).QueryRows(&items)
  207. return
  208. }
  209. // BaseFromHisugarIndex 泛糖科技
  210. type BaseFromHisugarIndex struct {
  211. BaseFromHisugarIndexId int `orm:"column(base_from_hisugar_index_id);pk"`
  212. ClassifyId int `description:"分类ID"`
  213. IndexCode string `description:"指标编码"`
  214. IndexName string `description:"指标名称"`
  215. Unit string `description:"单位"`
  216. Frequency string `description:"频度"`
  217. Source string `description:"数据来源"`
  218. Describe string `description:"指标描述"`
  219. Sort int `description:"排序"`
  220. StartDate time.Time `description:"开始日期"`
  221. EndDate time.Time `description:"结束日期"`
  222. LatestValue float64 `description:"最新值"`
  223. CreateTime time.Time `description:"创建时间"`
  224. ModifyTime time.Time `description:"更新时间"`
  225. }
  226. func (m *BaseFromHisugarIndex) SourceInfo() (int, int, string) {
  227. return utils.DATA_SOURCE_HISUGAR, 0, "泛糖科技"
  228. }
  229. func (m *BaseFromHisugarIndex) EsCols() SearchEsCols {
  230. return SearchEsCols{
  231. PrimaryId: "base_from_hisugar_index_id",
  232. IndexCode: "index_code",
  233. IndexName: "index_name",
  234. ClassifyId: "classify_id",
  235. Unit: "unit",
  236. Frequency: "frequency",
  237. StartDate: "start_date",
  238. EndDate: "end_date",
  239. LatestValue: "latest_value",
  240. CreateTime: "create_time",
  241. ModifyTime: "modify_time",
  242. }
  243. }
  244. func (m *BaseFromHisugarIndex) Format2SearchDataSource(origin *BaseFromHisugarIndex) (item *SearchDataSource) {
  245. if origin == nil {
  246. return
  247. }
  248. source, subSource, sourceName := m.SourceInfo()
  249. item = new(SearchDataSource)
  250. item.PrimaryId = origin.BaseFromHisugarIndexId
  251. item.IndexCode = origin.IndexCode
  252. item.IndexName = origin.IndexName
  253. item.ClassifyId = origin.ClassifyId
  254. item.Unit = origin.Unit
  255. item.Frequency = origin.Frequency
  256. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  257. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  258. item.LatestValue = origin.LatestValue
  259. item.Source = source
  260. item.SubSource = subSource
  261. item.SourceName = sourceName
  262. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  263. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  264. return
  265. }
  266. func (m *BaseFromHisugarIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromHisugarIndex, err error) {
  267. o := orm.NewOrmUsingDB("data")
  268. fields := strings.Join(fieldArr, ",")
  269. if len(fieldArr) == 0 {
  270. fields = `*`
  271. }
  272. order := `ORDER BY create_time DESC`
  273. if orderRule != "" {
  274. order = ` ORDER BY ` + orderRule
  275. }
  276. sql := fmt.Sprintf(`SELECT %s FROM base_from_hisugar_index WHERE 1=1 %s %s`, fields, condition, order)
  277. _, err = o.Raw(sql, pars).QueryRows(&items)
  278. return
  279. }
  280. // BaseFromLyIndex 粮油商务网
  281. type BaseFromLyIndex struct {
  282. BaseFromLyIndexId int `orm:"column(base_from_ly_index_id);pk"`
  283. BaseFromLyClassifyId int `description:"分类ID"`
  284. IndexCode string `description:"指标编码"`
  285. IndexName string `description:"指标名称"`
  286. Unit string `description:"单位"`
  287. Frequency string `description:"频度"`
  288. StartDate time.Time `description:"开始日期"`
  289. EndDate time.Time `description:"结束日期"`
  290. LatestValue float64 `description:"最新值"`
  291. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  292. CreateTime time.Time `description:"创建时间"`
  293. ModifyTime time.Time `description:"更新时间"`
  294. }
  295. func (m *BaseFromLyIndex) SourceInfo() (int, int, string) {
  296. return utils.DATA_SOURCE_LY, 0, "粮油商务网"
  297. }
  298. func (m *BaseFromLyIndex) EsCols() SearchEsCols {
  299. return SearchEsCols{
  300. PrimaryId: "base_from_ly_index_id",
  301. IndexCode: "index_code",
  302. IndexName: "index_name",
  303. ClassifyId: "base_from_ly_classify_id",
  304. Unit: "unit",
  305. Frequency: "frequency",
  306. StartDate: "start_date",
  307. EndDate: "end_date",
  308. LatestValue: "latest_value",
  309. CreateTime: "create_time",
  310. ModifyTime: "modify_time",
  311. }
  312. }
  313. func (m *BaseFromLyIndex) Format2SearchDataSource(origin *BaseFromLyIndex) (item *SearchDataSource) {
  314. if origin == nil {
  315. return
  316. }
  317. source, subSource, sourceName := m.SourceInfo()
  318. item = new(SearchDataSource)
  319. item.PrimaryId = origin.BaseFromLyIndexId
  320. item.IndexCode = origin.IndexCode
  321. item.IndexName = origin.IndexName
  322. item.ClassifyId = origin.BaseFromLyClassifyId
  323. item.Unit = origin.Unit
  324. item.Frequency = origin.Frequency
  325. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  326. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  327. item.LatestValue = origin.LatestValue
  328. item.Source = source
  329. item.SubSource = subSource
  330. item.SourceName = sourceName
  331. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  332. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  333. return
  334. }
  335. func (m *BaseFromLyIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromLyIndex, err error) {
  336. o := orm.NewOrmUsingDB("data")
  337. fields := strings.Join(fieldArr, ",")
  338. if len(fieldArr) == 0 {
  339. fields = `*`
  340. }
  341. order := `ORDER BY create_time DESC`
  342. if orderRule != "" {
  343. order = ` ORDER BY ` + orderRule
  344. }
  345. sql := fmt.Sprintf(`SELECT %s FROM base_from_ly_index WHERE 1=1 %s %s`, fields, condition, order)
  346. _, err = o.Raw(sql, pars).QueryRows(&items)
  347. return
  348. }
  349. // BaseFromSciHqIndex 卓创红期
  350. type BaseFromSciHqIndex struct {
  351. BaseFromSciHqIndexId int `orm:"column(base_from_sci_hq_index_id);pk"`
  352. ClassifyId int `description:"分类ID"`
  353. IndexCode string `description:"指标编码"`
  354. IndexName string `description:"指标名称"`
  355. Unit string `description:"单位"`
  356. Frequency string `description:"频度"`
  357. Sort int `description:"排序"`
  358. StartDate time.Time `description:"开始日期"`
  359. EndDate time.Time `description:"结束日期"`
  360. LatestValue float64 `description:"最新值"`
  361. LatestDate time.Time `description:"最新更新时间"`
  362. TerminalCode string `description:"指标描述"`
  363. FilePath string `description:"文件路径"`
  364. CreateTime time.Time `description:"创建时间"`
  365. ModifyTime time.Time `description:"更新时间"`
  366. }
  367. func (m *BaseFromSciHqIndex) SourceInfo() (int, int, string) {
  368. return utils.DATA_SOURCE_SCI_HQ, 0, "卓创红期"
  369. }
  370. func (m *BaseFromSciHqIndex) EsCols() SearchEsCols {
  371. return SearchEsCols{
  372. PrimaryId: "base_from_sci_hq_index_id",
  373. IndexCode: "index_code",
  374. IndexName: "index_name",
  375. ClassifyId: "classify_id",
  376. Unit: "unit",
  377. Frequency: "frequency",
  378. StartDate: "start_date",
  379. EndDate: "end_date",
  380. LatestValue: "latest_value",
  381. CreateTime: "create_time",
  382. ModifyTime: "modify_time",
  383. }
  384. }
  385. func (m *BaseFromSciHqIndex) Format2SearchDataSource(origin *BaseFromSciHqIndex) (item *SearchDataSource) {
  386. if origin == nil {
  387. return
  388. }
  389. source, subSource, sourceName := m.SourceInfo()
  390. item = new(SearchDataSource)
  391. item.PrimaryId = origin.BaseFromSciHqIndexId
  392. item.IndexCode = origin.IndexCode
  393. item.IndexName = origin.IndexName
  394. item.ClassifyId = origin.ClassifyId
  395. item.Unit = origin.Unit
  396. item.Frequency = origin.Frequency
  397. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  398. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  399. item.LatestValue = origin.LatestValue
  400. item.Source = source
  401. item.SubSource = subSource
  402. item.SourceName = sourceName
  403. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  404. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  405. return
  406. }
  407. func (m *BaseFromSciHqIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSciHqIndex, err error) {
  408. o := orm.NewOrmUsingDB("data")
  409. fields := strings.Join(fieldArr, ",")
  410. if len(fieldArr) == 0 {
  411. fields = `*`
  412. }
  413. order := `ORDER BY create_time DESC`
  414. if orderRule != "" {
  415. order = ` ORDER BY ` + orderRule
  416. }
  417. sql := fmt.Sprintf(`SELECT %s FROM base_from_sci_hq_index WHERE 1=1 %s %s`, fields, condition, order)
  418. _, err = o.Raw(sql, pars).QueryRows(&items)
  419. return
  420. }
  421. // BaseFromOilchemIndex 隆众资讯
  422. type BaseFromOilchemIndex struct {
  423. BaseFromOilchemIndexId int `orm:"column(base_from_oilchem_index_id);pk"`
  424. ClassifyId int `description:"分类ID"`
  425. IndexCode string `description:"指标编码"`
  426. IndexName string `description:"指标名称"`
  427. Unit string `description:"单位"`
  428. Frequency string `description:"频度"`
  429. StartDate time.Time `description:"开始日期"`
  430. EndDate time.Time `description:"结束日期"`
  431. LatestValue float64 `description:"最新值"`
  432. CreateTime time.Time `description:"创建时间"`
  433. ModifyTime time.Time `description:"更新时间"`
  434. }
  435. func (m *BaseFromOilchemIndex) SourceInfo() (int, int, string) {
  436. return utils.DATA_SOURCE_OILCHEM, 0, "隆众资讯"
  437. }
  438. func (m *BaseFromOilchemIndex) EsCols() SearchEsCols {
  439. return SearchEsCols{
  440. PrimaryId: "base_from_oilchem_index_id",
  441. IndexCode: "index_code",
  442. IndexName: "index_name",
  443. ClassifyId: "classify_id",
  444. Unit: "unit",
  445. Frequency: "frequency",
  446. StartDate: "start_date",
  447. EndDate: "end_date",
  448. LatestValue: "latest_value",
  449. CreateTime: "create_time",
  450. ModifyTime: "modify_time",
  451. }
  452. }
  453. func (m *BaseFromOilchemIndex) Format2SearchDataSource(origin *BaseFromOilchemIndex) (item *SearchDataSource) {
  454. if origin == nil {
  455. return
  456. }
  457. source, subSource, sourceName := m.SourceInfo()
  458. item = new(SearchDataSource)
  459. item.PrimaryId = origin.BaseFromOilchemIndexId
  460. item.IndexCode = origin.IndexCode
  461. item.IndexName = origin.IndexName
  462. item.ClassifyId = origin.ClassifyId
  463. item.Unit = origin.Unit
  464. item.Frequency = origin.Frequency
  465. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  466. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  467. item.LatestValue = origin.LatestValue
  468. item.Source = source
  469. item.SubSource = subSource
  470. item.SourceName = sourceName
  471. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  472. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  473. return
  474. }
  475. func (m *BaseFromOilchemIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromOilchemIndex, err error) {
  476. o := orm.NewOrmUsingDB("data")
  477. fields := strings.Join(fieldArr, ",")
  478. if len(fieldArr) == 0 {
  479. fields = `*`
  480. }
  481. order := `ORDER BY create_time DESC`
  482. if orderRule != "" {
  483. order = ` ORDER BY ` + orderRule
  484. }
  485. sql := fmt.Sprintf(`SELECT %s FROM base_from_oilchem_index WHERE 1=1 %s %s`, fields, condition, order)
  486. _, err = o.Raw(sql, pars).QueryRows(&items)
  487. return
  488. }
  489. // BaseFromThsHfIndex 同花顺高频数据
  490. type BaseFromThsHfIndex struct {
  491. BaseFromThsHfIndexId int `orm:"column(base_from_ths_hf_index_id);pk"`
  492. BaseFromThsHfClassifyId int `description:"分类ID"`
  493. IndexCode string `description:"指标编码"`
  494. IndexName string `description:"指标名称"`
  495. Unit string `description:"单位"`
  496. Source string `description:"数据来源"`
  497. Frequency string `description:"频度"`
  498. StartDate time.Time `description:"开始日期(至时分秒)"`
  499. EndDate time.Time `description:"结束日期(至时分秒)"`
  500. Describe string `description:"指标描述"`
  501. Sort int `description:"排序"`
  502. IsStop int `description:"是否停更:0-否;1-停更"`
  503. TerminalCode string `description:"所属终端编码"`
  504. StockCode string `description:"证券代码"`
  505. Indicator string `description:"同花顺指标代码"`
  506. ApiPars string `description:"API请求参数"`
  507. LatestValue float64 `description:"最新值"`
  508. SysUserId int `description:"创建人ID"`
  509. SysUserRealName string `description:"创建人姓名"`
  510. CreateTime time.Time `description:"创建时间"`
  511. ModifyTime time.Time `description:"修改时间"`
  512. }
  513. func (m *BaseFromThsHfIndex) SourceInfo() (int, int, string) {
  514. return utils.DATA_SOURCE_THS, utils.DATA_SUB_SOURCE_HIGH_FREQUENCY, "同花顺高频"
  515. }
  516. func (m *BaseFromThsHfIndex) EsCols() SearchEsCols {
  517. return SearchEsCols{
  518. PrimaryId: "base_from_ths_hf_index_id",
  519. IndexCode: "index_code",
  520. IndexName: "index_name",
  521. ClassifyId: "base_from_ths_hf_classify_id",
  522. Unit: "unit",
  523. Frequency: "frequency",
  524. StartDate: "start_date",
  525. EndDate: "end_date",
  526. LatestValue: "latest_value",
  527. CreateTime: "create_time",
  528. ModifyTime: "modify_time",
  529. }
  530. }
  531. func (m *BaseFromThsHfIndex) Format2SearchDataSource(origin *BaseFromThsHfIndex) (item *SearchDataSource) {
  532. if origin == nil {
  533. return
  534. }
  535. source, subSource, sourceName := m.SourceInfo()
  536. item = new(SearchDataSource)
  537. item.PrimaryId = origin.BaseFromThsHfIndexId
  538. item.IndexCode = origin.IndexCode
  539. item.IndexName = origin.IndexName
  540. item.ClassifyId = origin.BaseFromThsHfClassifyId
  541. item.Unit = origin.Unit
  542. item.Frequency = origin.Frequency
  543. item.StartDate = utils.TimeTransferString(utils.FormatDateTime, origin.StartDate) // 高频这里是到时分秒
  544. item.EndDate = utils.TimeTransferString(utils.FormatDateTime, origin.EndDate)
  545. item.LatestValue = origin.LatestValue
  546. item.Source = source
  547. item.SubSource = subSource
  548. item.SourceName = sourceName
  549. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  550. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  551. return
  552. }
  553. func (m *BaseFromThsHfIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromThsHfIndex, err error) {
  554. o := orm.NewOrmUsingDB("data")
  555. fields := strings.Join(fieldArr, ",")
  556. if len(fieldArr) == 0 {
  557. fields = `*`
  558. }
  559. order := `ORDER BY create_time DESC`
  560. if orderRule != "" {
  561. order = ` ORDER BY ` + orderRule
  562. }
  563. sql := fmt.Sprintf(`SELECT %s FROM base_from_ths_hf_index WHERE 1=1 %s %s`, fields, condition, order)
  564. _, err = o.Raw(sql, pars).QueryRows(&items)
  565. return
  566. }
  567. // BaseFromCcfIndex CCF化纤信息
  568. type BaseFromCcfIndex struct {
  569. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
  570. ClassifyId int `description:"分类ID"`
  571. IndexCode string `description:"指标编码"`
  572. IndexName string `description:"指标名称"`
  573. Unit string `description:"单位"`
  574. Frequency string `description:"频度"`
  575. StartDate time.Time `description:"开始日期"`
  576. EndDate time.Time `description:"结束日期"`
  577. LatestValue float64 `description:"最新值"`
  578. CreateTime time.Time `description:"创建时间"`
  579. ModifyTime time.Time `description:"更新时间"`
  580. }
  581. func (m *BaseFromCcfIndex) SourceInfo() (int, int, string) {
  582. return utils.DATA_SOURCE_CCF, 0, "CCF化纤信息"
  583. }
  584. func (m *BaseFromCcfIndex) EsCols() SearchEsCols {
  585. return SearchEsCols{
  586. PrimaryId: "base_from_ccf_index_id",
  587. IndexCode: "index_code",
  588. IndexName: "index_name",
  589. ClassifyId: "classify_id",
  590. Unit: "unit",
  591. Frequency: "frequency",
  592. StartDate: "start_date",
  593. EndDate: "end_date",
  594. LatestValue: "latest_value",
  595. CreateTime: "create_time",
  596. ModifyTime: "modify_time",
  597. }
  598. }
  599. func (m *BaseFromCcfIndex) Format2SearchDataSource(origin *BaseFromCcfIndex) (item *SearchDataSource) {
  600. if origin == nil {
  601. return
  602. }
  603. source, subSource, sourceName := m.SourceInfo()
  604. item = new(SearchDataSource)
  605. item.PrimaryId = origin.BaseFromCcfIndexId
  606. item.IndexCode = origin.IndexCode
  607. item.IndexName = origin.IndexName
  608. item.ClassifyId = origin.ClassifyId
  609. item.Unit = origin.Unit
  610. item.Frequency = origin.Frequency
  611. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  612. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  613. item.LatestValue = origin.LatestValue
  614. item.Source = source
  615. item.SubSource = subSource
  616. item.SourceName = sourceName
  617. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  618. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  619. return
  620. }
  621. func (m *BaseFromCcfIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromCcfIndex, err error) {
  622. o := orm.NewOrmUsingDB("data")
  623. fields := strings.Join(fieldArr, ",")
  624. if len(fieldArr) == 0 {
  625. fields = `*`
  626. }
  627. order := `ORDER BY create_time DESC`
  628. if orderRule != "" {
  629. order = ` ORDER BY ` + orderRule
  630. }
  631. sql := fmt.Sprintf(`SELECT %s FROM base_from_ccf_index WHERE 1=1 %s %s`, fields, condition, order)
  632. _, err = o.Raw(sql, pars).QueryRows(&items)
  633. return
  634. }
  635. // BaseFromUsdaFasIndex 美国农业部
  636. type BaseFromUsdaFasIndex struct {
  637. BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"`
  638. ClassifyId int `description:"分类ID"`
  639. IndexCode string `description:"指标编码"`
  640. IndexName string `description:"指标名称"`
  641. Unit string `description:"单位"`
  642. Frequency string `description:"频度"`
  643. StartDate time.Time `description:"开始日期"`
  644. EndDate time.Time `description:"结束日期"`
  645. LatestValue float64 `description:"最新值"`
  646. CreateTime time.Time `description:"创建时间"`
  647. ModifyTime time.Time `description:"更新时间"`
  648. }
  649. func (m *BaseFromUsdaFasIndex) SourceInfo() (int, int, string) {
  650. return utils.DATA_SOURCE_USDA_FAS, 0, "美国农业部"
  651. }
  652. func (m *BaseFromUsdaFasIndex) EsCols() SearchEsCols {
  653. return SearchEsCols{
  654. PrimaryId: "base_from_usda_fas_index_id",
  655. IndexCode: "index_code",
  656. IndexName: "index_name",
  657. ClassifyId: "classify_id",
  658. Unit: "unit",
  659. Frequency: "frequency",
  660. StartDate: "start_date",
  661. EndDate: "end_date",
  662. LatestValue: "end_value",
  663. CreateTime: "create_time",
  664. ModifyTime: "modify_time",
  665. }
  666. }
  667. func (m *BaseFromUsdaFasIndex) Format2SearchDataSource(origin *BaseFromUsdaFasIndex) (item *SearchDataSource) {
  668. if origin == nil {
  669. return
  670. }
  671. source, subSource, sourceName := m.SourceInfo()
  672. item = new(SearchDataSource)
  673. item.PrimaryId = origin.BaseFromUsdaFasIndexId
  674. item.IndexCode = origin.IndexCode
  675. item.IndexName = origin.IndexName
  676. item.ClassifyId = origin.ClassifyId
  677. item.Unit = origin.Unit
  678. item.Frequency = origin.Frequency
  679. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  680. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  681. item.LatestValue = origin.LatestValue
  682. item.Source = source
  683. item.SubSource = subSource
  684. item.SourceName = sourceName
  685. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  686. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  687. return
  688. }
  689. func (m *BaseFromUsdaFasIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromUsdaFasIndex, err error) {
  690. o := orm.NewOrmUsingDB("data")
  691. fields := strings.Join(fieldArr, ",")
  692. if len(fieldArr) == 0 {
  693. fields = `*`
  694. }
  695. order := `ORDER BY create_time DESC`
  696. if orderRule != "" {
  697. order = ` ORDER BY ` + orderRule
  698. }
  699. sql := fmt.Sprintf(`SELECT %s, end_value AS latest_value FROM base_from_usda_fas_index WHERE 1=1 %s %s`, fields, condition, order)
  700. _, err = o.Raw(sql, pars).QueryRows(&items)
  701. return
  702. }
  703. // BaseFromMysteelChemicalIndex 上海钢联
  704. type BaseFromMysteelChemicalIndex struct {
  705. BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id);pk"`
  706. BaseFromMysteelChemicalClassifyId int `description:"分类ID"`
  707. IndexCode string `description:"指标编码"`
  708. IndexName string `description:"指标名称"`
  709. Unit string `description:"单位"`
  710. Frequency string `description:"频度"`
  711. StartDate time.Time `description:"开始日期"`
  712. EndDate time.Time `description:"结束日期"`
  713. LatestValue float64 `description:"最新值"`
  714. CreateTime time.Time `description:"创建时间"`
  715. ModifyTime time.Time `description:"更新时间"`
  716. }
  717. func (m *BaseFromMysteelChemicalIndex) SourceInfo() (int, int, string) {
  718. return utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, "上海钢联"
  719. }
  720. func (m *BaseFromMysteelChemicalIndex) EsCols() SearchEsCols {
  721. return SearchEsCols{
  722. PrimaryId: "base_from_mysteel_chemical_index_id",
  723. IndexCode: "index_code",
  724. IndexName: "index_name",
  725. ClassifyId: "base_from_mysteel_chemical_classify_id",
  726. Unit: "unit",
  727. Frequency: "frequency",
  728. StartDate: "start_date",
  729. EndDate: "end_date",
  730. LatestValue: "end_value",
  731. CreateTime: "create_time",
  732. ModifyTime: "modify_time",
  733. }
  734. }
  735. func (m *BaseFromMysteelChemicalIndex) Format2SearchDataSource(origin *BaseFromMysteelChemicalIndex) (item *SearchDataSource) {
  736. if origin == nil {
  737. return
  738. }
  739. source, subSource, sourceName := m.SourceInfo()
  740. item = new(SearchDataSource)
  741. item.PrimaryId = origin.BaseFromMysteelChemicalIndexId
  742. item.IndexCode = origin.IndexCode
  743. item.IndexName = origin.IndexName
  744. item.ClassifyId = origin.BaseFromMysteelChemicalClassifyId
  745. item.Unit = origin.Unit
  746. item.Frequency = origin.Frequency
  747. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  748. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  749. item.LatestValue = origin.LatestValue
  750. item.Source = source
  751. item.SubSource = subSource
  752. item.SourceName = sourceName
  753. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  754. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  755. return
  756. }
  757. func (m *BaseFromMysteelChemicalIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromMysteelChemicalIndex, err error) {
  758. o := orm.NewOrmUsingDB("data")
  759. fields := strings.Join(fieldArr, ",")
  760. if len(fieldArr) == 0 {
  761. fields = `*`
  762. }
  763. order := `ORDER BY create_time DESC`
  764. if orderRule != "" {
  765. order = ` ORDER BY ` + orderRule
  766. }
  767. sql := fmt.Sprintf(`SELECT %s, end_value AS latest_value FROM base_from_mysteel_chemical_index WHERE 1=1 %s %s`, fields, condition, order)
  768. _, err = o.Raw(sql, pars).QueryRows(&items)
  769. return
  770. }
  771. // BaseFromSmmIndex 有色原始数据库
  772. type BaseFromSmmIndex struct {
  773. BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
  774. ClassifyId int `description:"分类ID"`
  775. IndexCode string `description:"指标编码"`
  776. IndexName string `description:"指标名称"`
  777. Unit string `description:"单位"`
  778. Frequency string `description:"频度"`
  779. StartDate time.Time `description:"开始日期"`
  780. EndDate time.Time `description:"结束日期"`
  781. LatestValue float64 `description:"最新值"`
  782. CreateTime time.Time `description:"创建时间"`
  783. ModifyTime time.Time `description:"更新时间"`
  784. }
  785. func (m *BaseFromSmmIndex) SourceInfo() (int, int, string) {
  786. return utils.DATA_SOURCE_YS, 0, "SMM原始数据库"
  787. }
  788. func (m *BaseFromSmmIndex) EsCols() SearchEsCols {
  789. return SearchEsCols{
  790. PrimaryId: "base_from_smm_index_id",
  791. IndexCode: "index_code",
  792. IndexName: "index_name",
  793. ClassifyId: "classify_id",
  794. Unit: "unit",
  795. Frequency: "frequency",
  796. StartDate: "start_date",
  797. EndDate: "end_date",
  798. LatestValue: "end_value",
  799. CreateTime: "create_time",
  800. ModifyTime: "modify_time",
  801. }
  802. }
  803. func (m *BaseFromSmmIndex) Format2SearchDataSource(origin *BaseFromSmmIndex) (item *SearchDataSource) {
  804. if origin == nil {
  805. return
  806. }
  807. source, subSource, sourceName := m.SourceInfo()
  808. item = new(SearchDataSource)
  809. item.PrimaryId = origin.BaseFromSmmIndexId
  810. item.IndexCode = origin.IndexCode
  811. item.IndexName = origin.IndexName
  812. item.ClassifyId = origin.ClassifyId
  813. item.Unit = origin.Unit
  814. item.Frequency = origin.Frequency
  815. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  816. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  817. item.LatestValue = origin.LatestValue
  818. item.Source = source
  819. item.SubSource = subSource
  820. item.SourceName = sourceName
  821. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  822. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  823. return
  824. }
  825. func (m *BaseFromSmmIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSmmIndex, err error) {
  826. o := orm.NewOrmUsingDB("data")
  827. fields := strings.Join(fieldArr, ",")
  828. if len(fieldArr) == 0 {
  829. fields = `*`
  830. }
  831. order := `ORDER BY create_time DESC`
  832. if orderRule != "" {
  833. order = ` ORDER BY ` + orderRule
  834. }
  835. sql := fmt.Sprintf(`SELECT %s, end_value AS latest_value FROM base_from_smm_index WHERE 1=1 %s %s`, fields, condition, order)
  836. _, err = o.Raw(sql, pars).QueryRows(&items)
  837. return
  838. }
  839. // BaseFromBaiinfoIndex 百川盈孚
  840. type BaseFromBaiinfoIndex struct {
  841. BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_index_id);pk"`
  842. ClassifyId int `description:"分类ID"`
  843. IndexCode string `description:"指标编码"`
  844. IndexName string `description:"指标名称"`
  845. Unit string `description:"单位"`
  846. Frequency string `description:"频度"`
  847. StartDate time.Time `description:"开始日期"`
  848. EndDate time.Time `description:"结束日期"`
  849. LatestValue float64 `description:"最新值"`
  850. CreateTime time.Time `description:"创建时间"`
  851. ModifyTime time.Time `description:"更新时间"`
  852. }
  853. func (m *BaseFromBaiinfoIndex) SourceInfo() (int, int, string) {
  854. return utils.DATA_SOURCE_BAIINFO, 0, "百川盈孚"
  855. }
  856. func (m *BaseFromBaiinfoIndex) EsCols() SearchEsCols {
  857. return SearchEsCols{
  858. PrimaryId: "base_from_baiinfo_index_id",
  859. IndexCode: "index_code",
  860. IndexName: "index_name",
  861. ClassifyId: "classify_id",
  862. Unit: "unit",
  863. Frequency: "frequency",
  864. StartDate: "start_date",
  865. EndDate: "end_date",
  866. LatestValue: "latest_value",
  867. CreateTime: "create_time",
  868. ModifyTime: "modify_time",
  869. }
  870. }
  871. func (m *BaseFromBaiinfoIndex) Format2SearchDataSource(origin *BaseFromBaiinfoIndex) (item *SearchDataSource) {
  872. if origin == nil {
  873. return
  874. }
  875. source, subSource, sourceName := m.SourceInfo()
  876. item = new(SearchDataSource)
  877. item.PrimaryId = origin.BaseFromBaiinfoIndexId
  878. item.IndexCode = origin.IndexCode
  879. item.IndexName = origin.IndexName
  880. item.ClassifyId = origin.ClassifyId
  881. item.Unit = origin.Unit
  882. item.Frequency = origin.Frequency
  883. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  884. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  885. item.LatestValue = origin.LatestValue
  886. item.Source = source
  887. item.SubSource = subSource
  888. item.SourceName = sourceName
  889. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  890. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  891. return
  892. }
  893. func (m *BaseFromBaiinfoIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromBaiinfoIndex, err error) {
  894. o := orm.NewOrmUsingDB("data")
  895. fields := strings.Join(fieldArr, ",")
  896. if len(fieldArr) == 0 {
  897. fields = `*`
  898. }
  899. order := `ORDER BY create_time DESC`
  900. if orderRule != "" {
  901. order = ` ORDER BY ` + orderRule
  902. }
  903. sql := fmt.Sprintf(`SELECT %s FROM base_from_baiinfo_index WHERE 1=1 %s %s`, fields, condition, order)
  904. _, err = o.Raw(sql, pars).QueryRows(&items)
  905. return
  906. }
  907. // BaseFromSciIndex 卓创数据(红桃3)
  908. type BaseFromSciIndex struct {
  909. BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"`
  910. ClassifyId int `description:"分类ID"`
  911. IndexCode string `description:"指标编码"`
  912. IndexName string `description:"指标名称"`
  913. Unit string `description:"单位"`
  914. Frequency string `description:"频度"`
  915. StartDate time.Time `description:"开始日期"`
  916. EndDate time.Time `description:"结束日期"`
  917. LatestValue float64 `description:"最新值"`
  918. CreateTime time.Time `description:"创建时间"`
  919. ModifyTime time.Time `description:"更新时间"`
  920. }
  921. func (m *BaseFromSciIndex) SourceInfo() (int, int, string) {
  922. return utils.DATA_SOURCE_SCI, 0, "卓创数据(红桃3)"
  923. }
  924. func (m *BaseFromSciIndex) EsCols() SearchEsCols {
  925. return SearchEsCols{
  926. PrimaryId: "base_from_sci_index_id",
  927. IndexCode: "index_code",
  928. IndexName: "index_name",
  929. ClassifyId: "classify_id",
  930. Unit: "unit",
  931. Frequency: "frequency",
  932. StartDate: "start_date",
  933. EndDate: "end_date",
  934. LatestValue: "latest_value",
  935. CreateTime: "create_time",
  936. ModifyTime: "modify_time",
  937. }
  938. }
  939. func (m *BaseFromSciIndex) Format2SearchDataSource(origin *BaseFromSciIndex) (item *SearchDataSource) {
  940. if origin == nil {
  941. return
  942. }
  943. source, subSource, sourceName := m.SourceInfo()
  944. item = new(SearchDataSource)
  945. item.PrimaryId = origin.BaseFromSciIndexId
  946. item.IndexCode = origin.IndexCode
  947. item.IndexName = origin.IndexName
  948. item.ClassifyId = origin.ClassifyId
  949. item.Unit = origin.Unit
  950. item.Frequency = origin.Frequency
  951. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  952. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  953. item.LatestValue = origin.LatestValue
  954. item.Source = source
  955. item.SubSource = subSource
  956. item.SourceName = sourceName
  957. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  958. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  959. return
  960. }
  961. func (m *BaseFromSciIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSciIndex, err error) {
  962. o := orm.NewOrmUsingDB("data")
  963. fields := strings.Join(fieldArr, ",")
  964. if len(fieldArr) == 0 {
  965. fields = `*`
  966. }
  967. order := `ORDER BY create_time DESC`
  968. if orderRule != "" {
  969. order = ` ORDER BY ` + orderRule
  970. }
  971. sql := fmt.Sprintf(`SELECT %s FROM base_from_sci_index WHERE 1=1 %s %s`, fields, condition, order)
  972. _, err = o.Raw(sql, pars).QueryRows(&items)
  973. return
  974. }
  975. // BaseFromCoalmineMapping 中国煤炭市场网
  976. type BaseFromCoalmineMapping struct {
  977. BaseFromCoalmineMappingId int `orm:"column(base_from_coalmine_mapping_id);pk"`
  978. ClassifyId int `description:"分类ID"`
  979. IndexCode string `description:"指标编码"`
  980. IndexName string `description:"指标名称"`
  981. Unit string `description:"单位"`
  982. Frequency string `description:"频度"`
  983. StartDate time.Time `description:"开始日期"`
  984. EndDate time.Time `description:"结束日期"`
  985. LatestValue float64 `description:"最新值"`
  986. CreateTime time.Time `description:"创建时间"`
  987. ModifyTime time.Time `description:"更新时间"`
  988. }
  989. func (m *BaseFromCoalmineMapping) SourceInfo() (int, int, string) {
  990. return utils.DATA_SOURCE_COAL, 0, "中国煤炭市场网"
  991. }
  992. func (m *BaseFromCoalmineMapping) EsCols() SearchEsCols {
  993. return SearchEsCols{
  994. PrimaryId: "base_from_coalmine_mapping_id",
  995. IndexCode: "index_code",
  996. IndexName: "index_name",
  997. ClassifyId: "",
  998. Unit: "",
  999. Frequency: "",
  1000. StartDate: "",
  1001. EndDate: "",
  1002. LatestValue: "",
  1003. CreateTime: "create_time",
  1004. ModifyTime: "",
  1005. }
  1006. }
  1007. func (m *BaseFromCoalmineMapping) Format2SearchDataSource(origin *BaseFromCoalmineMapping) (item *SearchDataSource) {
  1008. if origin == nil {
  1009. return
  1010. }
  1011. source, subSource, sourceName := m.SourceInfo()
  1012. item = new(SearchDataSource)
  1013. item.PrimaryId = origin.BaseFromCoalmineMappingId
  1014. item.IndexCode = origin.IndexCode
  1015. item.IndexName = origin.IndexName
  1016. item.ClassifyId = origin.ClassifyId
  1017. item.Unit = origin.Unit
  1018. item.Frequency = origin.Frequency
  1019. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1020. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1021. item.LatestValue = origin.LatestValue
  1022. item.Source = source
  1023. item.SubSource = subSource
  1024. item.SourceName = sourceName
  1025. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1026. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1027. return
  1028. }
  1029. func (m *BaseFromCoalmineMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromCoalmineMapping, err error) {
  1030. o := orm.NewOrmUsingDB("data")
  1031. fields := strings.Join(fieldArr, ",")
  1032. if len(fieldArr) == 0 {
  1033. fields = `*`
  1034. }
  1035. order := `ORDER BY create_time DESC`
  1036. if orderRule != "" {
  1037. order = ` ORDER BY ` + orderRule
  1038. }
  1039. sql := fmt.Sprintf(`SELECT %s FROM base_from_coalmine_mapping WHERE 1=1 %s %s`, fields, condition, order)
  1040. _, err = o.Raw(sql, pars).QueryRows(&items)
  1041. return
  1042. }
  1043. // BaseFromEiaSteoIndex EIA STEO报告
  1044. type BaseFromEiaSteoIndex struct {
  1045. BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"`
  1046. BaseFromEiaSteoClassifyId int `description:"分类ID"`
  1047. IndexCode string `description:"指标编码"`
  1048. IndexName string `description:"指标名称"`
  1049. Unit string `description:"单位"`
  1050. Frequency string `description:"频度"`
  1051. StartDate time.Time `description:"开始日期"`
  1052. EndDate time.Time `description:"结束日期"`
  1053. LatestValue float64 `description:"最新值"`
  1054. CreateTime time.Time `description:"创建时间"`
  1055. ModifyTime time.Time `description:"更新时间"`
  1056. }
  1057. func (m *BaseFromEiaSteoIndex) SourceInfo() (int, int, string) {
  1058. return utils.DATA_SOURCE_EIA_STEO, 0, "EIA STEO报告"
  1059. }
  1060. func (m *BaseFromEiaSteoIndex) EsCols() SearchEsCols {
  1061. return SearchEsCols{
  1062. PrimaryId: "base_from_eia_steo_index_id",
  1063. IndexCode: "index_code",
  1064. IndexName: "index_name",
  1065. ClassifyId: "base_from_eia_steo_classify_id",
  1066. Unit: "unit",
  1067. Frequency: "frequency",
  1068. StartDate: "start_date",
  1069. EndDate: "end_date",
  1070. LatestValue: "latest_value",
  1071. CreateTime: "create_time",
  1072. ModifyTime: "modify_time",
  1073. }
  1074. }
  1075. func (m *BaseFromEiaSteoIndex) Format2SearchDataSource(origin *BaseFromEiaSteoIndex) (item *SearchDataSource) {
  1076. if origin == nil {
  1077. return
  1078. }
  1079. source, subSource, sourceName := m.SourceInfo()
  1080. item = new(SearchDataSource)
  1081. item.PrimaryId = origin.BaseFromEiaSteoIndexId
  1082. item.IndexCode = origin.IndexCode
  1083. item.IndexName = origin.IndexName
  1084. item.ClassifyId = origin.BaseFromEiaSteoClassifyId
  1085. item.Unit = origin.Unit
  1086. item.Frequency = origin.Frequency
  1087. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1088. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1089. item.LatestValue = origin.LatestValue
  1090. item.Source = source
  1091. item.SubSource = subSource
  1092. item.SourceName = sourceName
  1093. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1094. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1095. return
  1096. }
  1097. func (m *BaseFromEiaSteoIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromEiaSteoIndex, err error) {
  1098. o := orm.NewOrmUsingDB("data")
  1099. fields := strings.Join(fieldArr, ",")
  1100. if len(fieldArr) == 0 {
  1101. fields = `*`
  1102. }
  1103. order := `ORDER BY create_time DESC`
  1104. if orderRule != "" {
  1105. order = ` ORDER BY ` + orderRule
  1106. }
  1107. sql := fmt.Sprintf(`SELECT %s FROM base_from_eia_steo_index WHERE 1=1 %s %s`, fields, condition, order)
  1108. _, err = o.Raw(sql, pars).QueryRows(&items)
  1109. return
  1110. }
  1111. // BaseFromIcpiIndex ICPI消费价格指数
  1112. type BaseFromIcpiIndex struct {
  1113. BaseFromIcpiIndexId int `orm:"column(base_from_icpi_index_id);pk"`
  1114. BaseFromIcpiClassifyId int `description:"分类ID"`
  1115. IndexCode string `description:"指标编码"`
  1116. IndexName string `description:"指标名称"`
  1117. Unit string `description:"单位"`
  1118. Frequency string `description:"频度"`
  1119. StartDate time.Time `description:"开始日期"`
  1120. EndDate time.Time `description:"结束日期"`
  1121. LatestValue float64 `description:"最新值"`
  1122. CreateTime time.Time `description:"创建时间"`
  1123. ModifyTime time.Time `description:"更新时间"`
  1124. }
  1125. func (m *BaseFromIcpiIndex) SourceInfo() (int, int, string) {
  1126. return utils.DATA_SOURCE_ICPI, 0, "ICPI消费价格指数"
  1127. }
  1128. func (m *BaseFromIcpiIndex) EsCols() SearchEsCols {
  1129. return SearchEsCols{
  1130. PrimaryId: "base_from_icpi_index_id",
  1131. IndexCode: "index_code",
  1132. IndexName: "index_name",
  1133. ClassifyId: "base_from_icpi_classify_id",
  1134. Unit: "unit",
  1135. Frequency: "frequency",
  1136. StartDate: "start_date",
  1137. EndDate: "end_date",
  1138. LatestValue: "latest_value",
  1139. CreateTime: "create_time",
  1140. ModifyTime: "modify_time",
  1141. }
  1142. }
  1143. func (m *BaseFromIcpiIndex) Format2SearchDataSource(origin *BaseFromIcpiIndex) (item *SearchDataSource) {
  1144. if origin == nil {
  1145. return
  1146. }
  1147. source, subSource, sourceName := m.SourceInfo()
  1148. item = new(SearchDataSource)
  1149. item.PrimaryId = origin.BaseFromIcpiIndexId
  1150. item.IndexCode = origin.IndexCode
  1151. item.IndexName = origin.IndexName
  1152. item.ClassifyId = origin.BaseFromIcpiClassifyId
  1153. item.Unit = origin.Unit
  1154. item.Frequency = origin.Frequency
  1155. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1156. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1157. item.LatestValue = origin.LatestValue
  1158. item.Source = source
  1159. item.SubSource = subSource
  1160. item.SourceName = sourceName
  1161. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1162. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1163. return
  1164. }
  1165. func (m *BaseFromIcpiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromIcpiIndex, err error) {
  1166. o := orm.NewOrmUsingDB("data")
  1167. fields := strings.Join(fieldArr, ",")
  1168. if len(fieldArr) == 0 {
  1169. fields = `*`
  1170. }
  1171. order := `ORDER BY create_time DESC`
  1172. if orderRule != "" {
  1173. order = ` ORDER BY ` + orderRule
  1174. }
  1175. sql := fmt.Sprintf(`SELECT %s FROM base_from_icpi_index WHERE 1=1 %s %s`, fields, condition, order)
  1176. _, err = o.Raw(sql, pars).QueryRows(&items)
  1177. return
  1178. }
  1179. // BaseFromYongyiIndex 涌益咨询
  1180. type BaseFromYongyiIndex struct {
  1181. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  1182. ClassifyId int `description:"分类ID"`
  1183. IndexCode string `description:"指标编码"`
  1184. IndexName string `description:"指标名称"`
  1185. Unit string `description:"单位"`
  1186. Frequency string `description:"频度"`
  1187. StartDate time.Time `description:"开始日期"`
  1188. EndDate time.Time `description:"结束日期"`
  1189. LatestValue float64 `description:"最新值"`
  1190. CreateTime time.Time `description:"创建时间"`
  1191. ModifyTime time.Time `description:"更新时间"`
  1192. }
  1193. func (m *BaseFromYongyiIndex) SourceInfo() (int, int, string) {
  1194. return utils.DATA_SOURCE_YONYI, 0, "涌益咨询"
  1195. }
  1196. func (m *BaseFromYongyiIndex) EsCols() SearchEsCols {
  1197. return SearchEsCols{
  1198. PrimaryId: "yongyi_index_id",
  1199. IndexCode: "index_code",
  1200. IndexName: "index_name",
  1201. ClassifyId: "classify_id",
  1202. Unit: "unit",
  1203. Frequency: "frequency",
  1204. StartDate: "start_date",
  1205. EndDate: "end_date",
  1206. LatestValue: "latest_value",
  1207. CreateTime: "create_time",
  1208. ModifyTime: "modify_time",
  1209. }
  1210. }
  1211. func (m *BaseFromYongyiIndex) Format2SearchDataSource(origin *BaseFromYongyiIndex) (item *SearchDataSource) {
  1212. if origin == nil {
  1213. return
  1214. }
  1215. source, subSource, sourceName := m.SourceInfo()
  1216. item = new(SearchDataSource)
  1217. item.PrimaryId = origin.YongyiIndexId
  1218. item.IndexCode = origin.IndexCode
  1219. item.IndexName = origin.IndexName
  1220. item.ClassifyId = origin.ClassifyId
  1221. item.Unit = origin.Unit
  1222. item.Frequency = origin.Frequency
  1223. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1224. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1225. item.LatestValue = origin.LatestValue
  1226. item.Source = source
  1227. item.SubSource = subSource
  1228. item.SourceName = sourceName
  1229. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1230. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1231. return
  1232. }
  1233. func (m *BaseFromYongyiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromYongyiIndex, err error) {
  1234. o := orm.NewOrmUsingDB("data")
  1235. fields := strings.Join(fieldArr, ",")
  1236. if len(fieldArr) == 0 {
  1237. fields = `*`
  1238. }
  1239. order := `ORDER BY create_time DESC`
  1240. if orderRule != "" {
  1241. order = ` ORDER BY ` + orderRule
  1242. }
  1243. sql := fmt.Sprintf(`SELECT %s FROM base_from_yongyi_index WHERE 1=1 %s %s`, fields, condition, order)
  1244. _, err = o.Raw(sql, pars).QueryRows(&items)
  1245. return
  1246. }
  1247. // BaseFromFenweiIndex 汾渭数据
  1248. type BaseFromFenweiIndex struct {
  1249. FenweiIndexId int `orm:"column(fenwei_index_id);pk"`
  1250. ClassifyId int `description:"分类ID"`
  1251. IndexCode string `description:"指标编码"`
  1252. IndexName string `description:"指标名称"`
  1253. Unit string `description:"单位"`
  1254. Frequency string `description:"频度"`
  1255. StartDate time.Time `description:"开始日期"`
  1256. EndDate time.Time `description:"结束日期"`
  1257. LatestValue float64 `description:"最新值"`
  1258. CreateTime time.Time `description:"创建时间"`
  1259. ModifyTime time.Time `description:"更新时间"`
  1260. }
  1261. func (m *BaseFromFenweiIndex) SourceInfo() (int, int, string) {
  1262. return utils.DATA_SOURCE_FENWEI, 0, "汾渭数据"
  1263. }
  1264. func (m *BaseFromFenweiIndex) EsCols() SearchEsCols {
  1265. return SearchEsCols{
  1266. PrimaryId: "fenwei_index_id",
  1267. IndexCode: "index_code",
  1268. IndexName: "index_name",
  1269. ClassifyId: "classify_id",
  1270. Unit: "unit",
  1271. Frequency: "frequency",
  1272. StartDate: "start_date",
  1273. EndDate: "end_date",
  1274. LatestValue: "latest_value",
  1275. CreateTime: "create_time",
  1276. ModifyTime: "modify_time",
  1277. }
  1278. }
  1279. func (m *BaseFromFenweiIndex) Format2SearchDataSource(origin *BaseFromFenweiIndex) (item *SearchDataSource) {
  1280. if origin == nil {
  1281. return
  1282. }
  1283. source, subSource, sourceName := m.SourceInfo()
  1284. item = new(SearchDataSource)
  1285. item.PrimaryId = origin.FenweiIndexId
  1286. item.IndexCode = origin.IndexCode
  1287. item.IndexName = origin.IndexName
  1288. item.ClassifyId = origin.ClassifyId
  1289. item.Unit = origin.Unit
  1290. item.Frequency = origin.Frequency
  1291. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1292. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1293. item.LatestValue = origin.LatestValue
  1294. item.Source = source
  1295. item.SubSource = subSource
  1296. item.SourceName = sourceName
  1297. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1298. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1299. return
  1300. }
  1301. func (m *BaseFromFenweiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromFenweiIndex, err error) {
  1302. o := orm.NewOrmUsingDB("data")
  1303. fields := strings.Join(fieldArr, ",")
  1304. if len(fieldArr) == 0 {
  1305. fields = `*`
  1306. }
  1307. order := `ORDER BY create_time DESC`
  1308. if orderRule != "" {
  1309. order = ` ORDER BY ` + orderRule
  1310. }
  1311. sql := fmt.Sprintf(`SELECT %s FROM base_from_fenwei_index WHERE 1=1 %s %s`, fields, condition, order)
  1312. _, err = o.Raw(sql, pars).QueryRows(&items)
  1313. return
  1314. }
  1315. // BaseFromSci99Index 卓创资讯
  1316. type BaseFromSci99Index struct {
  1317. BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"`
  1318. ClassifyId int `description:"分类ID"`
  1319. IndexCode string `description:"指标编码"`
  1320. IndexName string `description:"指标名称"`
  1321. Unit string `description:"单位"`
  1322. Frequency string `description:"频度"`
  1323. StartDate time.Time `description:"开始日期"`
  1324. EndDate time.Time `description:"结束日期"`
  1325. LatestValue float64 `description:"最新值"`
  1326. CreateTime time.Time `description:"创建时间"`
  1327. ModifyTime time.Time `description:"更新时间"`
  1328. }
  1329. func (m *BaseFromSci99Index) SourceInfo() (int, int, string) {
  1330. return utils.DATA_SOURCE_SCI99, 0, "卓创资讯"
  1331. }
  1332. func (m *BaseFromSci99Index) EsCols() SearchEsCols {
  1333. return SearchEsCols{
  1334. PrimaryId: "base_from_sci_index_id",
  1335. IndexCode: "index_code",
  1336. IndexName: "index_name",
  1337. ClassifyId: "classify_id",
  1338. Unit: "unit",
  1339. Frequency: "frequency",
  1340. StartDate: "start_date",
  1341. EndDate: "end_date",
  1342. LatestValue: "latest_value",
  1343. CreateTime: "create_time",
  1344. ModifyTime: "modify_time",
  1345. }
  1346. }
  1347. func (m *BaseFromSci99Index) Format2SearchDataSource(origin *BaseFromSci99Index) (item *SearchDataSource) {
  1348. if origin == nil {
  1349. return
  1350. }
  1351. source, subSource, sourceName := m.SourceInfo()
  1352. item = new(SearchDataSource)
  1353. item.PrimaryId = origin.BaseFromSciIndexId
  1354. item.IndexCode = origin.IndexCode
  1355. item.IndexName = origin.IndexName
  1356. item.ClassifyId = origin.ClassifyId
  1357. item.Unit = origin.Unit
  1358. item.Frequency = origin.Frequency
  1359. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1360. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1361. item.LatestValue = origin.LatestValue
  1362. item.Source = source
  1363. item.SubSource = subSource
  1364. item.SourceName = sourceName
  1365. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1366. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1367. return
  1368. }
  1369. func (m *BaseFromSci99Index) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSci99Index, err error) {
  1370. o := orm.NewOrmUsingDB("data")
  1371. fields := strings.Join(fieldArr, ",")
  1372. if len(fieldArr) == 0 {
  1373. fields = `*`
  1374. }
  1375. order := `ORDER BY create_time DESC`
  1376. if orderRule != "" {
  1377. order = ` ORDER BY ` + orderRule
  1378. }
  1379. sql := fmt.Sprintf(`SELECT %s FROM base_from_sci99_index WHERE 1=1 %s %s`, fields, condition, order)
  1380. _, err = o.Raw(sql, pars).QueryRows(&items)
  1381. return
  1382. }
  1383. // BaseFromGlIndex 钢联原始指标库
  1384. type BaseFromGlIndex struct {
  1385. PrimaryId int `orm:"column(ID);pk"`
  1386. IndexCode string `orm:"column(INDEX_CODE)" description:"指标编码"`
  1387. IndexName string `orm:"column(INDEX_NAME)" description:"指标名称"`
  1388. Unit string `orm:"column(UNIT_NAME)" description:"单位"`
  1389. Frequency string `orm:"column(FREQUENCY_NAME)" description:"频度"`
  1390. StartDate time.Time `orm:"column(BEGIN_DATE)" description:"开始日期"`
  1391. EndDate time.Time `orm:"column(END_DATE)" description:"结束日期"`
  1392. LatestValue float64 `orm:"column(DATA_VALUE)" description:"最新值"`
  1393. CreateTime time.Time `orm:"column(CREATE_TIME)" description:"创建时间"`
  1394. ModifyTime time.Time `orm:"column(UPDATE_TIME)" description:"更新时间"`
  1395. }
  1396. func (m *BaseFromGlIndex) SourceInfo() (int, int, string) {
  1397. return utils.DATA_SOURCE_GL, 0, "钢联原始数据库"
  1398. }
  1399. func (m *BaseFromGlIndex) EsCols() SearchEsCols {
  1400. return SearchEsCols{
  1401. PrimaryId: "ID",
  1402. IndexCode: "INDEX_CODE",
  1403. IndexName: "INDEX_NAME",
  1404. ClassifyId: "",
  1405. Unit: "UNIT_NAME",
  1406. Frequency: "FREQUENCY_NAME",
  1407. StartDate: "BEGIN_DATE",
  1408. EndDate: "END_DATE",
  1409. LatestValue: "DATA_VALUE",
  1410. CreateTime: "CREATE_TIME",
  1411. ModifyTime: "UPDATE_TIME",
  1412. }
  1413. }
  1414. func (m *BaseFromGlIndex) Format2SearchDataSource(origin *BaseFromGlIndex) (item *SearchDataSource) {
  1415. if origin == nil {
  1416. return
  1417. }
  1418. source, subSource, sourceName := m.SourceInfo()
  1419. item = new(SearchDataSource)
  1420. item.PrimaryId = origin.PrimaryId
  1421. item.IndexCode = origin.IndexCode
  1422. item.IndexName = origin.IndexName
  1423. //item.ClassifyId = origin.ClassifyId
  1424. item.Unit = origin.Unit
  1425. item.Frequency = origin.Frequency
  1426. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1427. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1428. item.LatestValue = origin.LatestValue
  1429. item.Source = source
  1430. item.SubSource = subSource
  1431. item.SourceName = sourceName
  1432. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1433. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1434. return
  1435. }
  1436. func (m *BaseFromGlIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromGlIndex, err error) {
  1437. o := orm.NewOrmUsingDB("gl")
  1438. fields := strings.Join(fieldArr, ",")
  1439. if len(fieldArr) == 0 {
  1440. fields = `*`
  1441. }
  1442. order := `ORDER BY CREATE_TIME DESC`
  1443. if orderRule != "" {
  1444. order = ` ORDER BY ` + orderRule
  1445. }
  1446. sql := fmt.Sprintf(`SELECT %s FROM mb_index_main_info WHERE 1=1 %s %s`, fields, condition, order)
  1447. _, err = o.Raw(sql, pars).QueryRows(&items)
  1448. return
  1449. }
  1450. // BaseFromManualEdb 手工数据录入
  1451. type BaseFromManualEdb struct {
  1452. //PrimaryId int `orm:"column(TRADE_CODE)"` // 注手工指标没自增ID...
  1453. IndexCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
  1454. IndexName string `orm:"column(SEC_NAME)" description:"指标名称"`
  1455. ClassifyId int `orm:"column(classify_id)" description:"分类ID"`
  1456. Unit string `orm:"column(UNIT)" description:"单位"`
  1457. Frequency string `orm:"column(frequency)" description:"频度"`
  1458. StartDate time.Time `orm:"column(start_date)" description:"开始日期"`
  1459. EndDate time.Time `orm:"column(end_date)" description:"结束日期"`
  1460. LatestValue float64 `orm:"column(latest_value)" description:"最新值"`
  1461. CreateTime time.Time `orm:"column(create_date)" description:"创建时间"`
  1462. ModifyTime time.Time `orm:"column(modify_time)" description:"更新时间"`
  1463. }
  1464. func (m *BaseFromManualEdb) SourceInfo() (int, int, string) {
  1465. return utils.DATA_SOURCE_MANUAL, 0, "手工指标录入"
  1466. }
  1467. func (m *BaseFromManualEdb) EsCols() SearchEsCols {
  1468. return SearchEsCols{
  1469. PrimaryId: "",
  1470. IndexCode: "TRADE_CODE",
  1471. IndexName: "SEC_NAME",
  1472. ClassifyId: "classify_id",
  1473. Unit: "UNIT",
  1474. Frequency: "frequency",
  1475. StartDate: "start_date",
  1476. EndDate: "end_date",
  1477. LatestValue: "latest_value",
  1478. CreateTime: "create_date",
  1479. ModifyTime: "modify_time",
  1480. }
  1481. }
  1482. func (m *BaseFromManualEdb) Format2SearchDataSource(origin *BaseFromManualEdb) (item *SearchDataSource) {
  1483. if origin == nil {
  1484. return
  1485. }
  1486. source, subSource, sourceName := m.SourceInfo()
  1487. item = new(SearchDataSource)
  1488. //item.PrimaryId = origin.PrimaryId
  1489. item.IndexCode = origin.IndexCode
  1490. item.IndexName = origin.IndexName
  1491. item.ClassifyId = origin.ClassifyId
  1492. item.Unit = origin.Unit
  1493. item.Frequency = origin.Frequency
  1494. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1495. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1496. item.LatestValue = origin.LatestValue
  1497. item.Source = source
  1498. item.SubSource = subSource
  1499. item.SourceName = sourceName
  1500. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1501. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1502. return
  1503. }
  1504. func (m *BaseFromManualEdb) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromManualEdb, err error) {
  1505. o := orm.NewOrmUsingDB("edb")
  1506. fields := strings.Join(fieldArr, ",")
  1507. if len(fieldArr) == 0 {
  1508. fields = `*`
  1509. }
  1510. order := `ORDER BY create_date DESC`
  1511. if orderRule != "" {
  1512. order = ` ORDER BY ` + orderRule
  1513. }
  1514. sql := fmt.Sprintf(`SELECT %s FROM edbinfo WHERE 1=1 %s %s`, fields, condition, order)
  1515. _, err = o.Raw(sql, pars).QueryRows(&items)
  1516. return
  1517. }
  1518. // BaseFromBusinessIndex 自有数据
  1519. type BaseFromBusinessIndex struct {
  1520. BaseFromBusinessIndexId int `orm:"column(base_from_business_index_id);pk"`
  1521. //ClassifyId int `description:"分类ID"`
  1522. IndexCode string `description:"指标编码"`
  1523. IndexName string `description:"指标名称"`
  1524. Unit string `description:"单位"`
  1525. Frequency string `description:"频度"`
  1526. StartDate time.Time `description:"开始日期"`
  1527. EndDate time.Time `description:"结束日期"`
  1528. LatestValue float64 `description:"最新值"`
  1529. CreateTime time.Time `description:"创建时间"`
  1530. ModifyTime time.Time `description:"更新时间"`
  1531. }
  1532. func (m *BaseFromBusinessIndex) SourceInfo() (int, int, string) {
  1533. return utils.DATA_SOURCE_BUSINESS, 0, "自有数据"
  1534. }
  1535. func (m *BaseFromBusinessIndex) EsCols() SearchEsCols {
  1536. return SearchEsCols{
  1537. PrimaryId: "base_from_business_index_id",
  1538. IndexCode: "index_code",
  1539. IndexName: "index_name",
  1540. ClassifyId: "",
  1541. Unit: "unit",
  1542. Frequency: "frequency",
  1543. StartDate: "start_date",
  1544. EndDate: "end_date",
  1545. LatestValue: "latest_value",
  1546. CreateTime: "create_time",
  1547. ModifyTime: "modify_time",
  1548. }
  1549. }
  1550. func (m *BaseFromBusinessIndex) Format2SearchDataSource(origin *BaseFromBusinessIndex) (item *SearchDataSource) {
  1551. if origin == nil {
  1552. return
  1553. }
  1554. source, subSource, sourceName := m.SourceInfo()
  1555. item = new(SearchDataSource)
  1556. item.PrimaryId = origin.BaseFromBusinessIndexId
  1557. item.IndexCode = origin.IndexCode
  1558. item.IndexName = origin.IndexName
  1559. //item.ClassifyId = origin.ClassifyId
  1560. item.Unit = origin.Unit
  1561. item.Frequency = origin.Frequency
  1562. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1563. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1564. item.LatestValue = origin.LatestValue
  1565. item.Source = source
  1566. item.SubSource = subSource
  1567. item.SourceName = sourceName
  1568. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1569. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1570. return
  1571. }
  1572. func (m *BaseFromBusinessIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromBusinessIndex, err error) {
  1573. o := orm.NewOrmUsingDB("data")
  1574. fields := strings.Join(fieldArr, ",")
  1575. if len(fieldArr) == 0 {
  1576. fields = `*`
  1577. }
  1578. order := `ORDER BY create_time DESC`
  1579. if orderRule != "" {
  1580. order = ` ORDER BY ` + orderRule
  1581. }
  1582. sql := fmt.Sprintf(`SELECT %s FROM base_from_business_index WHERE 1=1 %s %s`, fields, condition, order)
  1583. _, err = o.Raw(sql, pars).QueryRows(&items)
  1584. return
  1585. }
  1586. // BaseFromBloombergIndex Bloomberg
  1587. type BaseFromBloombergIndex struct {
  1588. BaseFromBloombergIndexId int `orm:"column(base_from_bloomberg_index_id);pk"`
  1589. //ClassifyId int `description:"分类ID"`
  1590. IndexCode string `description:"指标编码"`
  1591. IndexName string `description:"指标名称"`
  1592. Unit string `description:"单位"`
  1593. Frequency string `description:"频度"`
  1594. StartDate time.Time `description:"开始日期"`
  1595. EndDate time.Time `description:"结束日期"`
  1596. LatestValue float64 `description:"最新值"`
  1597. CreateTime time.Time `description:"创建时间"`
  1598. ModifyTime time.Time `description:"更新时间"`
  1599. }
  1600. func (m *BaseFromBloombergIndex) SourceInfo() (int, int, string) {
  1601. return utils.DATA_SOURCE_BLOOMBERG, 0, "Bloomberg"
  1602. }
  1603. func (m *BaseFromBloombergIndex) EsCols() SearchEsCols {
  1604. return SearchEsCols{
  1605. PrimaryId: "base_from_bloomberg_index_id",
  1606. IndexCode: "index_code",
  1607. IndexName: "index_name",
  1608. ClassifyId: "",
  1609. Unit: "unit",
  1610. Frequency: "frequency",
  1611. StartDate: "start_date",
  1612. EndDate: "end_date",
  1613. LatestValue: "latest_value",
  1614. CreateTime: "create_time",
  1615. ModifyTime: "modify_time",
  1616. }
  1617. }
  1618. func (m *BaseFromBloombergIndex) Format2SearchDataSource(origin *BaseFromBloombergIndex) (item *SearchDataSource) {
  1619. if origin == nil {
  1620. return
  1621. }
  1622. source, subSource, sourceName := m.SourceInfo()
  1623. item = new(SearchDataSource)
  1624. item.PrimaryId = origin.BaseFromBloombergIndexId
  1625. item.IndexCode = origin.IndexCode
  1626. item.IndexName = origin.IndexName
  1627. //item.ClassifyId = origin.ClassifyId
  1628. item.Unit = origin.Unit
  1629. item.Frequency = origin.Frequency
  1630. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1631. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1632. item.LatestValue = origin.LatestValue
  1633. item.Source = source
  1634. item.SubSource = subSource
  1635. item.SourceName = sourceName
  1636. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1637. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1638. return
  1639. }
  1640. func (m *BaseFromBloombergIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromBloombergIndex, err error) {
  1641. o := orm.NewOrmUsingDB("data")
  1642. fields := strings.Join(fieldArr, ",")
  1643. if len(fieldArr) == 0 {
  1644. fields = `*`
  1645. }
  1646. order := `ORDER BY create_time DESC`
  1647. if orderRule != "" {
  1648. order = ` ORDER BY ` + orderRule
  1649. }
  1650. sql := fmt.Sprintf(`SELECT %s FROM base_from_bloomberg_index WHERE 1=1 %s %s`, fields, condition, order)
  1651. _, err = o.Raw(sql, pars).QueryRows(&items)
  1652. return
  1653. }
  1654. // BaseFromMtjhMapping 煤炭江湖
  1655. type BaseFromMtjhMapping struct {
  1656. BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"`
  1657. //ClassifyId int `description:"分类ID"`
  1658. IndexCode string `description:"指标编码"`
  1659. IndexName string `description:"指标名称"`
  1660. Unit string `description:"单位"`
  1661. Frequency string `description:"频度"`
  1662. StartDate time.Time `description:"开始日期"`
  1663. EndDate time.Time `description:"结束日期"`
  1664. LatestValue float64 `description:"最新值"`
  1665. CreateTime time.Time `description:"创建时间"`
  1666. ModifyTime time.Time `description:"更新时间"`
  1667. }
  1668. func (m *BaseFromMtjhMapping) SourceInfo() (int, int, string) {
  1669. return utils.DATA_SOURCE_MTJH, 0, "煤炭江湖"
  1670. }
  1671. func (m *BaseFromMtjhMapping) EsCols() SearchEsCols {
  1672. return SearchEsCols{
  1673. PrimaryId: "base_from_mtjh_mapping_id",
  1674. IndexCode: "index_code",
  1675. IndexName: "index_name",
  1676. ClassifyId: "",
  1677. Unit: "unit",
  1678. Frequency: "frequency",
  1679. StartDate: "start_date",
  1680. EndDate: "end_date",
  1681. LatestValue: "latest_value",
  1682. CreateTime: "create_time",
  1683. ModifyTime: "",
  1684. }
  1685. }
  1686. func (m *BaseFromMtjhMapping) Format2SearchDataSource(origin *BaseFromMtjhMapping) (item *SearchDataSource) {
  1687. if origin == nil {
  1688. return
  1689. }
  1690. source, subSource, sourceName := m.SourceInfo()
  1691. item = new(SearchDataSource)
  1692. item.PrimaryId = origin.BaseFromMtjhMappingId
  1693. item.IndexCode = origin.IndexCode
  1694. item.IndexName = origin.IndexName
  1695. //item.ClassifyId = origin.ClassifyId
  1696. item.Unit = origin.Unit
  1697. item.Frequency = origin.Frequency
  1698. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  1699. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  1700. item.LatestValue = origin.LatestValue
  1701. item.Source = source
  1702. item.SubSource = subSource
  1703. item.SourceName = sourceName
  1704. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  1705. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  1706. return
  1707. }
  1708. func (m *BaseFromMtjhMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromMtjhMapping, err error) {
  1709. o := orm.NewOrmUsingDB("data")
  1710. fields := strings.Join(fieldArr, ",")
  1711. if len(fieldArr) == 0 {
  1712. fields = `*`
  1713. }
  1714. order := `ORDER BY create_time DESC`
  1715. if orderRule != "" {
  1716. order = ` ORDER BY ` + orderRule
  1717. }
  1718. sql := fmt.Sprintf(`SELECT %s FROM base_from_mtjh_mapping WHERE 1=1 %s %s`, fields, condition, order)
  1719. _, err = o.Raw(sql, pars).QueryRows(&items)
  1720. return
  1721. }
  1722. // BaseIndexDataMinMax 数据源极值信息
  1723. type BaseIndexDataMinMax struct {
  1724. MinDate string `description:"最小日期"`
  1725. MaxDate string `description:"最大日期"`
  1726. LatestValue float64 `description:"最新值"`
  1727. //MinValue float64 `description:"最小值"`
  1728. //MaxValue float64 `description:"最大值"`
  1729. }
  1730. // GetBaseIndexDataTableName 根据来源获取原始指标表和数据表名(很大一部分来源不存在原始指标)
  1731. func GetBaseIndexDataTableName(source, subSource int) (indexTable, dataTable string) {
  1732. switch source {
  1733. case utils.DATA_SOURCE_THS:
  1734. if subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY {
  1735. indexTable = "base_from_ths_hf_index"
  1736. dataTable = "base_from_ths_hf_data"
  1737. }
  1738. case utils.DATA_SOURCE_RZD:
  1739. indexTable = "base_from_rzd_index"
  1740. dataTable = "base_from_rzd_data"
  1741. case utils.DATA_SOURCE_HISUGAR:
  1742. indexTable = "base_from_hisugar_index"
  1743. dataTable = "base_from_hisugar_data"
  1744. case utils.DATA_SOURCE_LY:
  1745. indexTable = "base_from_ly_index"
  1746. dataTable = "base_from_ly_data"
  1747. case utils.DATA_SOURCE_SCI_HQ:
  1748. indexTable = "base_from_sci_hq_index"
  1749. dataTable = "base_from_sci_hq_data"
  1750. case utils.DATA_SOURCE_OILCHEM:
  1751. indexTable = "base_from_oilchem_index"
  1752. dataTable = "base_from_oilchem_data"
  1753. case utils.DATA_SOURCE_CCF:
  1754. indexTable = "base_from_ccf_index"
  1755. dataTable = "base_from_ccf_data"
  1756. case utils.DATA_SOURCE_USDA_FAS:
  1757. indexTable = "base_from_usda_fas_index"
  1758. dataTable = "base_from_usda_fas_data"
  1759. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  1760. indexTable = "base_from_mysteel_chemical_index"
  1761. dataTable = "base_from_mysteel_chemical_data"
  1762. case utils.DATA_SOURCE_YS:
  1763. indexTable = "base_from_smm_index"
  1764. dataTable = "base_from_smm_data"
  1765. case utils.DATA_SOURCE_BAIINFO:
  1766. indexTable = "base_from_baiinfo_index"
  1767. dataTable = "base_from_baiinfo_data"
  1768. case utils.DATA_SOURCE_SCI:
  1769. indexTable = "base_from_sci_index"
  1770. dataTable = "base_from_sci_data"
  1771. case utils.DATA_SOURCE_EIA_STEO:
  1772. indexTable = "base_from_eia_steo_index"
  1773. dataTable = "base_from_eia_steo_data"
  1774. case utils.DATA_SOURCE_ICPI:
  1775. indexTable = "base_from_icpi_index"
  1776. dataTable = "base_from_icpi_data"
  1777. case utils.DATA_SOURCE_YONYI:
  1778. indexTable = "base_from_yongyi_index"
  1779. dataTable = "base_from_yongyi_data"
  1780. case utils.DATA_SOURCE_FENWEI:
  1781. indexTable = "base_from_fenwei_index"
  1782. dataTable = "base_from_fenwei_data"
  1783. case utils.DATA_SOURCE_SCI99:
  1784. indexTable = "base_from_icpi_index"
  1785. dataTable = "base_from_icpi_data"
  1786. case utils.DATA_SOURCE_BUSINESS:
  1787. indexTable = "base_from_business_index"
  1788. dataTable = "base_from_business_data"
  1789. case utils.DATA_SOURCE_BLOOMBERG:
  1790. indexTable = "base_from_bloomberg_index"
  1791. dataTable = "base_from_bloomberg_data"
  1792. default:
  1793. utils.FileLog.Info(fmt.Sprintf("数据源无对应表名, source: %d, sub: %d", source, subSource))
  1794. }
  1795. return
  1796. }
  1797. // getCoalmineDataTableName 获取中国煤炭市场网数据表名
  1798. func getCoalmineDataTableName(indexCode string) string {
  1799. if strings.Contains(indexCode, "jsm") {
  1800. return "base_from_coalmine_jsm_index"
  1801. }
  1802. if strings.Contains(indexCode, "company") {
  1803. return "base_from_coalmine_company_index"
  1804. }
  1805. if strings.Contains(indexCode, "firm") {
  1806. return "base_from_coalmine_firm_index"
  1807. }
  1808. if strings.Contains(indexCode, "coastal") {
  1809. return "base_from_coalmine_coastal_index"
  1810. }
  1811. if strings.Contains(indexCode, "inland") {
  1812. return "base_from_coalmine_inland_index"
  1813. }
  1814. return ""
  1815. }
  1816. // GetBaseIndexDataMinMax 获取数据源极值
  1817. func GetBaseIndexDataMinMax(source, subSource int, indexCode string) (item *BaseIndexDataMinMax, err error) {
  1818. o := orm.NewOrmUsingDB("data")
  1819. var sql string
  1820. var latestVal float64
  1821. // 煤炭江湖
  1822. if source == utils.DATA_SOURCE_MTJH {
  1823. sql = `SELECT MIN(data_time) AS min_date, MAX(data_time) AS max_date FROM base_from_mtjh_index WHERE index_code = ?`
  1824. if e := o.Raw(sql, indexCode).QueryRow(&item); e != nil {
  1825. err = fmt.Errorf("获取数据源开始结束时间失败, %v", e)
  1826. return
  1827. }
  1828. sql = `SELECT deal_value AS latest_value FROM base_from_mtjh_index WHERE index_code = ? ORDER BY data_time DESC LIMIT 1`
  1829. if e := o.Raw(sql, indexCode).QueryRow(&latestVal); e != nil {
  1830. err = fmt.Errorf("获取数据源最新值失败, %v", e)
  1831. return
  1832. }
  1833. item.LatestValue = latestVal
  1834. return
  1835. }
  1836. // 中国煤炭市场网
  1837. if source == utils.DATA_SOURCE_COAL {
  1838. dataTable := getCoalmineDataTableName(indexCode)
  1839. if dataTable == "" {
  1840. err = fmt.Errorf("中国煤炭市场网-指标无对应表名: %s", indexCode)
  1841. return
  1842. }
  1843. fieldDataTime := "data_time"
  1844. if dataTable == "base_from_coalmine_firm_index" {
  1845. fieldDataTime = "data_time_date"
  1846. }
  1847. sql = `SELECT MIN(%s) AS min_date, MAX(%s) AS max_date FROM %s WHERE index_code = ?`
  1848. sql = fmt.Sprintf(sql, fieldDataTime, fieldDataTime, dataTable)
  1849. if e := o.Raw(sql, indexCode).QueryRow(&item); e != nil {
  1850. err = fmt.Errorf("获取数据源开始结束时间失败, %v", e)
  1851. return
  1852. }
  1853. sql = `SELECT deal_value AS latest_value FROM %s WHERE index_code = ? ORDER BY %s DESC LIMIT 1`
  1854. sql = fmt.Sprintf(sql, dataTable, fieldDataTime)
  1855. if e := o.Raw(sql, indexCode).QueryRow(&latestVal); e != nil {
  1856. err = fmt.Errorf("获取数据源最新值失败, %v", e)
  1857. return
  1858. }
  1859. item.LatestValue = latestVal
  1860. return
  1861. }
  1862. // 其他数据源
  1863. _, dataTable := GetBaseIndexDataTableName(source, subSource)
  1864. if dataTable == "" {
  1865. err = fmt.Errorf("数据源无对应数据表, source: %d, sub: %d, code: %s", source, subSource, indexCode)
  1866. return
  1867. }
  1868. sql = `SELECT MIN(data_time) AS min_date, MAX(data_time) AS max_date FROM %s WHERE index_code = ?`
  1869. sql = fmt.Sprintf(sql, dataTable)
  1870. if e := o.Raw(sql, indexCode).QueryRow(&item); e != nil {
  1871. err = fmt.Errorf("获取数据源开始结束时间失败, %v", e)
  1872. return
  1873. }
  1874. sql = `SELECT value AS latest_value FROM %s WHERE index_code = ? ORDER BY data_time DESC LIMIT 1`
  1875. sql = fmt.Sprintf(sql, dataTable)
  1876. if e := o.Raw(sql, indexCode).QueryRow(&latestVal); e != nil {
  1877. err = fmt.Errorf("获取数据源最新值失败, %v", e)
  1878. return
  1879. }
  1880. item.LatestValue = latestVal
  1881. return
  1882. }