data_source.go 80 KB

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