edb_info.go 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models/data_manage/line_equation/request"
  5. "eta/eta_api/models/mgo"
  6. "eta/eta_api/services/alarm_msg"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "go.mongodb.org/mongo-driver/bson"
  13. "github.com/beego/beego/v2/client/orm"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. )
  16. // EdbInfoOrm
  17. // @Description: 数据库映射结构体
  18. type EdbInfoOrm struct {
  19. EdbInfoId int `orm:"column(edb_info_id);pk;auto"`
  20. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  21. SourceName string `description:"来源名称"`
  22. Source int `description:"来源id"`
  23. EdbCode string `description:"指标编码"`
  24. EdbName string `description:"指标名称"`
  25. EdbNameEn string `description:"英文指标名称"`
  26. EdbNameSource string `description:"指标名称来源"`
  27. Frequency string `description:"频率"`
  28. Unit string `description:"单位"`
  29. UnitEn string `description:"英文单位"`
  30. StartDate time.Time `description:"起始日期"`
  31. EndDate time.Time `description:"终止日期"`
  32. ClassifyId int `description:"分类id"`
  33. SysUserId int
  34. SysUserRealName string
  35. UniqueCode string `description:"指标唯一编码"`
  36. CreateTime time.Time
  37. ModifyTime time.Time
  38. BaseModifyTime time.Time
  39. MinValue float64 `description:"指标最小值"`
  40. MaxValue float64 `description:"指标最大值"`
  41. CalculateFormula string `description:"计算公式"`
  42. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  43. Sort int `description:"排序字段"`
  44. LatestDate time.Time `description:"数据最新日期(实际日期)"`
  45. LatestValue float64 `description:"数据最新值(实际值)"`
  46. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  47. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  48. MoveFrequency string `description:"移动频度"`
  49. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  50. ServerUrl string `description:"服务器地址"`
  51. ChartImage string `description:"图表图片"`
  52. Calendar string `description:"公历/农历" orm:"default(公历);"`
  53. DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  54. ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"`
  55. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  56. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  57. TerminalCode string `description:"终端编码,用于配置在机器上"`
  58. DataUpdateTime time.Time `description:"最近一次数据发生变化的时间"`
  59. ErDataUpdateDate time.Time `description:"本次更新,数据发生变化的最早日期"`
  60. SourceIndexName string `description:"数据源中的指标名称"`
  61. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  62. SubSourceName string `description:"子数据来源名称"`
  63. IndicatorCode string `description:"指标代码"`
  64. StockCode string `description:"证券代码"`
  65. Extra string `description:"指标额外配置"`
  66. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  67. IsStaticData int `description:"是否是静态指标,0否,1是"`
  68. SetUpdateTime time.Time `description:"设置启用/禁用刷新状态的时间"`
  69. EndDateType int `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
  70. }
  71. type EdbInfo struct {
  72. EdbInfoId int `orm:"column(edb_info_id);pk;auto"`
  73. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  74. SourceName string `description:"来源名称"`
  75. Source int `description:"来源id"`
  76. EdbCode string `description:"指标编码"`
  77. EdbName string `description:"指标名称"`
  78. EdbNameEn string `description:"英文指标名称"`
  79. EdbNameSource string `description:"指标名称来源"`
  80. Frequency string `description:"频率"`
  81. Unit string `description:"单位"`
  82. UnitEn string `description:"英文单位"`
  83. StartDate string `description:"起始日期"`
  84. EndDate string `description:"终止日期"`
  85. ClassifyId int `description:"分类id"`
  86. SysUserId int
  87. SysUserRealName string
  88. UniqueCode string `description:"指标唯一编码"`
  89. CreateTime time.Time
  90. ModifyTime time.Time
  91. BaseModifyTime time.Time
  92. MinValue float64 `description:"指标最小值"`
  93. MaxValue float64 `description:"指标最大值"`
  94. CalculateFormula string `description:"计算公式"`
  95. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  96. Sort int `description:"排序字段"`
  97. LatestDate string `description:"数据最新日期(实际日期)"`
  98. LatestValue float64 `description:"数据最新值(实际值)"`
  99. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  100. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  101. MoveFrequency string `description:"移动频度"`
  102. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  103. ServerUrl string `description:"服务器地址"`
  104. ChartImage string `description:"图表图片"`
  105. Calendar string `description:"公历/农历" orm:"default(公历);"`
  106. DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  107. ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"`
  108. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  109. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  110. TerminalCode string `description:"终端编码,用于配置在机器上"`
  111. DataUpdateTime string `description:"最近一次数据发生变化的时间"`
  112. ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
  113. SourceIndexName string `description:"数据源中的指标名称"`
  114. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  115. SubSourceName string `description:"子数据来源名称"`
  116. IndicatorCode string `description:"指标代码"`
  117. StockCode string `description:"证券代码"`
  118. Extra string `description:"指标额外配置"`
  119. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  120. IsStaticData int `description:"是否是静态指标,0否,1是"`
  121. SetUpdateTime time.Time `description:"设置启用/禁用刷新状态的时间"`
  122. EndDateType int `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
  123. }
  124. type EdbInfoFullClassify struct {
  125. *EdbInfo
  126. CorrelationStr string `description:"相关性系数字符串"`
  127. ClassifyList []*EdbClassifyIdItems
  128. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  129. IsSupplierStop int `description:"是否供应商停更:1:停更,0:未停更"`
  130. }
  131. func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
  132. o := orm.NewOrmUsingDB("data")
  133. lastId, err = o.Insert(item)
  134. return
  135. }
  136. type BaseEdbNameItem struct {
  137. EdbInfoId int `description:"指标id"`
  138. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  139. SourceName string `description:"来源名称"`
  140. Source int `description:"来源id"`
  141. EdbCode string `description:"指标编码"`
  142. EdbName string `description:"指标名称"`
  143. EdbNameEn string `description:"指标英文名称"`
  144. Frequency string `description:"频率"`
  145. Unit string `description:"单位"`
  146. UnitEn string `description:"英文单位"`
  147. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  148. }
  149. type BaseEdbInfoResp struct {
  150. List []*BaseEdbNameItem
  151. }
  152. // GetEdbInfoAll 用于分类展示
  153. func GetEdbInfoAll(edbInfoType uint8) (items []*EdbClassifyItems, err error) {
  154. o := orm.NewOrmUsingDB("data")
  155. sql := ` SELECT edb_info_id,classify_id,edb_name_source AS classify_name,edb_name_en AS classify_name_en,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type FROM edb_info WHERE edb_info_type = ? order by sort asc,edb_info_id asc`
  156. _, err = o.Raw(sql, edbInfoType).QueryRows(&items)
  157. return
  158. }
  159. // GetPredictEdbInfoAll 用于分类展示(预测指标)
  160. func GetPredictEdbInfoAll(edbInfoType uint8) (items []*EdbClassifyItems, err error) {
  161. o := orm.NewOrmUsingDB("data")
  162. sql := ` SELECT edb_info_id,classify_id,edb_name AS classify_name,edb_name_en AS classify_name_en,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type FROM edb_info WHERE edb_info_type = ? order by sort asc,edb_info_id asc`
  163. _, err = o.Raw(sql, edbInfoType).QueryRows(&items)
  164. return
  165. }
  166. // 用于分类展示
  167. func GetEdbInfoAllList() (items []*EdbInfo, err error) {
  168. var ormList []*EdbInfoOrm
  169. items = make([]*EdbInfo, 0)
  170. o := orm.NewOrmUsingDB("data")
  171. sql := ` SELECT * FROM edb_info `
  172. _, err = o.Raw(sql).QueryRows(&ormList)
  173. if err != nil {
  174. return
  175. }
  176. for _, ormItem := range ormList {
  177. items = append(items, ormItem.ToInfo())
  178. }
  179. return
  180. }
  181. // 指标检索数据
  182. type EdbInfoSearch struct {
  183. EdbCode string `description:"指标编码"`
  184. StartDate string `description:"起始日期"`
  185. EndDate string `description:"终止日期"`
  186. EdbName string `description:"指标名称"`
  187. Unit string `description:"单位"`
  188. Frequency string `description:"频率"`
  189. DataList []*EdbInfoSearchData
  190. StockList []*StockInfo `description:"时序数据"`
  191. }
  192. type StockInfo struct {
  193. StockCode string
  194. EdbCode string
  195. DataList []*EdbInfoSearchData
  196. }
  197. type EdbInfoSearchData struct {
  198. DataTime string `description:"数据日期"`
  199. Value float64 `description:"数据"`
  200. }
  201. type BaseIndexInfo struct {
  202. IndexName string `description:"数据日期"`
  203. Unit string `description:"单位"`
  204. Frequency string `description:"频率"`
  205. }
  206. type EdbInfoSearchResp struct {
  207. SearchItem *EdbInfoSearch `description:"指标分类"`
  208. Status int `description:"1:数据已存在于弘则数据库,2:新数据,3:数据已存在于弘则数据库,但是当前账号无权限"`
  209. ClassifyList []*EdbClassifySimplify
  210. StockSearchList []*EdbInfoSearch
  211. }
  212. type EdbInfoMySteelChemicalCheckResp struct {
  213. Status int `description:"1:数据已存在于弘则数据库,2:新数据,3:数据已存在于弘则数据库,但是当前账号无权限"`
  214. }
  215. func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error) {
  216. var edbInfoOrm *EdbInfoOrm
  217. o := orm.NewOrmUsingDB("data")
  218. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code=? `
  219. err = o.Raw(sql, source, edbCode).QueryRow(&edbInfoOrm)
  220. if err != nil {
  221. return
  222. }
  223. item = edbInfoOrm.ToInfo()
  224. return
  225. }
  226. func GetEdbInfoListByEdbCodes(source int, edbCodes []string) (items []*EdbInfo, err error) {
  227. if len(edbCodes) == 0 {
  228. return
  229. }
  230. var ormList []*EdbInfoOrm
  231. items = make([]*EdbInfo, 0)
  232. o := orm.NewOrmUsingDB("data")
  233. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code IN (` + utils.GetOrmInReplace(len(edbCodes)) + `) `
  234. _, err = o.Raw(sql, source, edbCodes).QueryRows(&ormList)
  235. if err != nil {
  236. return
  237. }
  238. for _, ormItem := range ormList {
  239. items = append(items, ormItem.ToInfo())
  240. }
  241. return
  242. }
  243. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  244. var edbInfoOrm *EdbInfoOrm
  245. o := orm.NewOrmUsingDB("data")
  246. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  247. err = o.Raw(sql, edbInfoId).QueryRow(&edbInfoOrm)
  248. if err != nil {
  249. return
  250. }
  251. item = edbInfoOrm.ToInfo()
  252. return
  253. }
  254. type EdbInfoExt struct {
  255. EdbInfoId int `orm:"column(edb_info_id);pk"`
  256. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  257. SourceName string `description:"来源名称"`
  258. Source int `description:"来源id"`
  259. EdbCode string `description:"指标编码"`
  260. EdbName string `description:"指标名称"`
  261. EdbNameEn string `description:"英文指标名称"`
  262. EdbNameSource string `description:"指标名称来源"`
  263. Frequency string `description:"频率"`
  264. Unit string `description:"单位"`
  265. UnitEn string `description:"英文单位"`
  266. StartDate time.Time `description:"起始日期"`
  267. EndDate string `description:"终止日期"`
  268. ClassifyId int `description:"分类id"`
  269. SysUserId int
  270. SysUserRealName string
  271. UniqueCode string `description:"指标唯一编码"`
  272. CreateTime time.Time
  273. ModifyTime time.Time
  274. BaseModifyTime time.Time
  275. MinValue float64 `description:"指标最小值"`
  276. MaxValue float64 `description:"指标最大值"`
  277. CalculateFormula string `description:"计算公式"`
  278. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  279. Sort int `description:"排序字段"`
  280. LatestDate string `description:"数据最新日期(实际日期)"`
  281. LatestValue float64 `description:"数据最新值(实际值)"`
  282. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  283. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  284. MoveFrequency string `description:"移动频度"`
  285. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  286. ServerUrl string `description:"服务器地址"`
  287. ChartImage string `description:"图表图片"`
  288. Calendar string `description:"公历/农历" orm:"default(公历);"`
  289. DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  290. ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"`
  291. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  292. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  293. TerminalCode string `description:"终端编码,用于配置在机器上"`
  294. DataUpdateTime string `description:"最近一次数据发生变化的时间"`
  295. ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
  296. SourceIndexName string `description:"数据源中的指标名称"`
  297. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  298. SubSourceName string `description:"子数据来源名称"`
  299. IndicatorCode string `description:"指标代码"`
  300. StockCode string `description:"证券代码"`
  301. Extra string `description:"指标额外配置"`
  302. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  303. IsStaticData int `description:"是否是静态指标,0否,1是"`
  304. SetUpdateTime time.Time `description:"设置启用/禁用刷新状态的时间"`
  305. EndDateType int `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
  306. }
  307. func GetEdbInfoByIdExt(edbInfoId int) (item *EdbInfoExt, err error) {
  308. o := orm.NewOrmUsingDB("data")
  309. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  310. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  311. return
  312. }
  313. // GetEdbInfoByUniqueCode
  314. // @Description: 根据uniqueCode获取指标详情
  315. // @author: Roc
  316. // @datetime 2024-01-18 13:40:01
  317. // @param uniqueCode string
  318. // @return item *EdbInfo
  319. // @return err error
  320. func GetEdbInfoByUniqueCode(uniqueCode string) (item *EdbInfo, err error) {
  321. var edbInfoOrm *EdbInfoOrm
  322. o := orm.NewOrmUsingDB("data")
  323. sql := ` SELECT * FROM edb_info WHERE unique_code=? `
  324. err = o.Raw(sql, uniqueCode).QueryRow(&edbInfoOrm)
  325. if err != nil {
  326. return
  327. }
  328. item = edbInfoOrm.ToInfo()
  329. return
  330. }
  331. // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
  332. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  333. num := len(edbInfoIdList)
  334. if num <= 0 {
  335. return
  336. }
  337. var ormList []*EdbInfoOrm
  338. items = make([]*EdbInfo, 0)
  339. o := orm.NewOrmUsingDB("data")
  340. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  341. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&ormList)
  342. if err != nil {
  343. return
  344. }
  345. for _, ormItem := range ormList {
  346. items = append(items, ormItem.ToInfo())
  347. }
  348. return
  349. }
  350. // type MysteelChemicalDataListReq struct {
  351. // Frequency string `form:"Frequency" description:"频度"`
  352. // Source int `form:"Source" description:"来源id"`
  353. // Keywords string `form:"Keywords" description:"指标ID/指标名称"`
  354. // SortField int `form:"SortField" description:"排序字段: 0-默认; 1-开始时间; 2-最新时间; 3-更新时间"`
  355. // SortRule int `form:"SortRule" description:"排序方式: 0-默认; 1-正序; 2-倒序"`
  356. // }
  357. // BatchAddCheckReq 指标批量添加校验
  358. type BatchAddCheckReq struct {
  359. IndexCodes []string `form:"IndexCodes" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  360. }
  361. // MysteelChemicalDataBatchAddCheckReq 钢联化工指标批量添加校验
  362. type MysteelChemicalDataBatchAddCheckReq struct {
  363. // MysteelChemicalDataListReq
  364. IndexCodes []string `form:"IndexCodes" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  365. }
  366. type EiaSteoDataBatchAddCheckReq struct {
  367. IndexCodes []string `description:"指标编码"`
  368. }
  369. type AddEdbInfoReq struct {
  370. Source int `description:"来源id"`
  371. EdbCode string `description:"指标编码"`
  372. EdbName string `description:"指标名称"`
  373. Frequency string `description:"频率"`
  374. Unit string `description:"单位"`
  375. ClassifyId int `description:"分类id"`
  376. StartDate string `description:"起始日期"`
  377. EndDate string `description:"终止日期"`
  378. }
  379. type NameCheckEdbInfoReq struct {
  380. EdbCode string `description:"指标编码"`
  381. EdbName string `description:"指标名称"`
  382. Frequency string `description:"频率"`
  383. }
  384. func DeleteEdbInfoAndData(edbInfoId, source, subSource int) (err error) {
  385. o := orm.NewOrmUsingDB("data")
  386. to, err := o.Begin()
  387. if err != nil {
  388. return
  389. }
  390. defer func() {
  391. if err != nil {
  392. _ = to.Rollback()
  393. } else {
  394. _ = to.Commit()
  395. }
  396. }()
  397. // 删除指标信息
  398. sql := ` DELETE FROM edb_info WHERE edb_info_id=? `
  399. _, err = to.Raw(sql, edbInfoId).Exec()
  400. if err != nil {
  401. return
  402. }
  403. // 删除指标的明细数据
  404. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  405. err = deleteAllEdbDataByMongo(to, edbInfoId, source, subSource)
  406. } else if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  407. mogDataObj := mgo.EdbDataThsHf{}
  408. err = mogDataObj.RemoveMany(bson.M{"edb_info_id": edbInfoId})
  409. } else {
  410. err = deleteAllEdbDataByMysql(to, edbInfoId, source, subSource)
  411. }
  412. if err != nil {
  413. return
  414. }
  415. //calculateTableName := GetEdbInfoCalculateTableName(source)
  416. //if calculateTableName != "" {
  417. // sql = ` DELETE FROM %s WHERE edb_info_id=? `
  418. // sql = fmt.Sprintf(sql, calculateTableName)
  419. // _, err = to.Raw(sql, edbInfoId).Exec()
  420. // return
  421. //}
  422. //return
  423. // 删除计算指标的关系
  424. sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
  425. _, err = to.Raw(sql, edbInfoId).Exec()
  426. if err != nil {
  427. return
  428. }
  429. // 删除预测指标的配置
  430. sql = ` DELETE FROM predict_edb_conf WHERE predict_edb_info_id=? `
  431. _, err = to.Raw(sql, edbInfoId).Exec()
  432. if err != nil {
  433. return
  434. }
  435. // 删除跨品种分析标签绑定的指标
  436. sql = ` DELETE FROM chart_tag_variety WHERE edb_info_id=?`
  437. _, err = to.Raw(sql, edbInfoId).Exec()
  438. if err != nil {
  439. return
  440. }
  441. // 删除stl趋势分解指标的映射关系
  442. sql = ` DELETE FROM calculate_stl_config_mapping WHERE edb_info_id=?`
  443. _, err = to.Raw(sql, edbInfoId).Exec()
  444. if err != nil {
  445. return
  446. }
  447. return
  448. }
  449. // deleteAllEdbDataByMysql
  450. // @Description: 删除指标的明细数据(mysql)
  451. // @author: Roc
  452. // @datetime 2024-05-09 13:31:54
  453. // @param to orm.TxOrmer
  454. // @param edbInfoId int
  455. // @param source int
  456. // @param subSource int
  457. // @return err error
  458. func deleteAllEdbDataByMysql(to orm.TxOrmer, edbInfoId, source, subSource int) (err error) {
  459. tableName := GetEdbDataTableName(source, subSource)
  460. if tableName == `` {
  461. return
  462. }
  463. sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id=? `, tableName)
  464. _, err = to.Raw(sql, edbInfoId).Exec()
  465. return
  466. }
  467. // deleteAllEdbDataByMongo
  468. // @Description: 删除指标的明细数据(mongo)
  469. // @author: Roc
  470. // @datetime 2024-05-09 13:31:37
  471. // @param to orm.TxOrmer
  472. // @param edbInfoId int
  473. // @param source int
  474. // @param subSource int
  475. // @return err error
  476. func deleteAllEdbDataByMongo(to orm.TxOrmer, edbInfoId, source, subSource int) (err error) {
  477. mogDataObj := mgo.EdbDataBusiness{}
  478. err = mogDataObj.RemoveMany(bson.M{"edb_info_id": edbInfoId})
  479. return
  480. }
  481. func GetEdbInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  482. o := orm.NewOrmUsingDB("data")
  483. sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
  484. if condition != "" {
  485. sql += condition
  486. }
  487. err = o.Raw(sql, pars).QueryRow(&count)
  488. return
  489. }
  490. type EditEdbInfoReq struct {
  491. EdbInfoId int `description:"指标ID"`
  492. EdbName string `description:"指标名称"`
  493. Frequency string `description:"频率"`
  494. Unit string `description:"单位"`
  495. ClassifyId int `description:"分类id"`
  496. CalculateFormula string `description:"计算公式"`
  497. }
  498. type EditEdbEnInfoReq struct {
  499. EdbInfoId int `description:"指标ID"`
  500. EdbNameEn string `description:"英文指标名称"`
  501. UnitEn string `description:"英文单位"`
  502. }
  503. // EditEdbBaseInfoReq
  504. // @Description: 修改指标基础信息请求参数
  505. type EditEdbBaseInfoReq struct {
  506. EdbInfoId int `description:"指标ID"`
  507. EdbName string `description:"指标名称"`
  508. Unit string `description:"指标单位"`
  509. }
  510. func ModifyEdbInfo(item *EditEdbInfoReq) (err error) {
  511. o := orm.NewOrmUsingDB("data")
  512. sql := ` UPDATE edb_info
  513. SET
  514. edb_name =?,
  515. edb_name_source =?,
  516. frequency = ?,
  517. unit = ?,
  518. classify_id = ?,
  519. modify_time = NOW()
  520. WHERE edb_info_id = ?`
  521. _, err = o.Raw(sql, item.EdbName, item.EdbName, item.Frequency, item.Unit, item.ClassifyId, item.EdbInfoId).Exec()
  522. return
  523. }
  524. // ModifyEdbEnInfo 修改指标英文信息
  525. func ModifyEdbEnInfo(item *EditEdbEnInfoReq) (err error) {
  526. o := orm.NewOrmUsingDB("data")
  527. sql := ` UPDATE edb_info
  528. SET
  529. edb_name_en =?,
  530. unit_en = ?,
  531. modify_time = NOW()
  532. WHERE edb_info_id = ?`
  533. _, err = o.Raw(sql, item.EdbNameEn, item.UnitEn, item.EdbInfoId).Exec()
  534. return
  535. }
  536. type EdbInfoList struct {
  537. EdbInfoId int `orm:"column(edb_info_id);pk"`
  538. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  539. SourceName string `description:"来源名称"`
  540. Source int `description:"来源id"`
  541. EdbCode string `description:"指标编码"`
  542. EdbNameEn string `description:"英文指标名称"`
  543. EdbName string `description:"指标名称"`
  544. Frequency string `description:"频率"`
  545. FrequencyEn string `description:"英文频率"`
  546. Unit string `description:"单位"`
  547. UnitEn string `description:"英文单位"`
  548. StartDate string `description:"起始日期"`
  549. EndDate string `description:"终止日期"`
  550. LatestDate string `description:"数据最新日期(实际日期)"`
  551. LatestValue float64 `description:"数据最新值(实际值)"`
  552. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  553. ClassifyId int `description:"分类id"`
  554. UniqueCode string `description:"指标唯一编码"`
  555. SysUserId int `description:"创建人id"`
  556. SysUserRealName string `description:"创建人姓名"`
  557. ModifyTime string `description:"最新修改时间"`
  558. CreateTime string `description:"创建时间"`
  559. EdbNameAlias string `json:"-" description:"指标名称,别名"`
  560. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  561. ChartImage string `description:"图表图片"`
  562. RuleType int `description:"预测规则,1:最新,2:固定值"`
  563. FixedValue float64 `description:"固定值"`
  564. DataList []*EdbData `description:"实际指标数据"`
  565. PredictDataList []*EdbData `description:"预测指标数据"`
  566. Button EdbClassifyItemsButton `description:"操作权限"`
  567. IsEnEdb bool `description:"是否展示英文标识"`
  568. DataInsertConfig EdbDataInsertConfigItem `description:"指标数据插入配置"`
  569. DataDateType string `description:"数据日期类型,枚举值:交易日、自然日"`
  570. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  571. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  572. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  573. SubSourceName string `description:"子数据来源名称"`
  574. IndicatorCode string `description:"指标代码"`
  575. StockCode string `description:"证券代码"`
  576. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  577. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  578. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  579. IsStaticData int `description:"是否是静态指标,0否,1是"`
  580. IsSupplierStop int `description:"是否供应商停更:1:停更,0:未停更"`
  581. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  582. MoveFrequency string `description:"移动频度"`
  583. MinValue float64 `description:"最小值"`
  584. MaxValue float64 `description:"最大值"`
  585. SearchText string `description:"搜索结果(含高亮)"`
  586. }
  587. type EdbDataInsertConfigItem struct {
  588. Date string `description:"插入的日期"`
  589. RealDate string `description:"实际最晚的日期"`
  590. Value string `description:"插入的值"`
  591. }
  592. type EdbData struct {
  593. EdbDataId int `orm:"column(edb_data_id);pk"`
  594. EdbInfoId int
  595. DataTime string
  596. Value float64
  597. }
  598. type EdbDataOrm struct {
  599. EdbDataId int `orm:"column(edb_data_id);pk"`
  600. EdbInfoId int
  601. DataTime time.Time
  602. Value float64
  603. }
  604. type EdbInfoListResp struct {
  605. Paging *paging.PagingItem
  606. Item *EdbInfoList
  607. ClassifyList []*EdbClassifyIdItems
  608. }
  609. type WindEdbInfoList struct {
  610. *EdbInfoList
  611. ClassifyList []*EdbClassifyIdItems
  612. }
  613. func GetEdbInfoByCondition(condition string, pars []interface{}) (item *EdbInfoList, err error) {
  614. o := orm.NewOrmUsingDB("data")
  615. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  616. if condition != "" {
  617. sql += condition
  618. }
  619. // [2025-zsh-时间类型修复-chenhan]
  620. var ormItem *EdbInfoOrm
  621. err = o.Raw(sql, pars).QueryRow(&ormItem)
  622. if err != nil {
  623. return
  624. }
  625. item = ormItem.ToList()
  626. return
  627. }
  628. func GetEdbDataCountByCondition(condition string, pars []interface{}, source, subSource int) (count int, err error) {
  629. o := orm.NewOrmUsingDB("data")
  630. tableName := GetEdbDataTableName(source, subSource)
  631. sql := ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
  632. sql = fmt.Sprintf(sql, tableName)
  633. if condition != "" {
  634. sql += condition
  635. }
  636. err = o.Raw(sql, pars).QueryRow(&count)
  637. return
  638. }
  639. func GetEdbDataListByCondition(condition string, pars []interface{}, source, subSource, pageSize, startSize int) (item []*EdbData, err error) {
  640. o := orm.NewOrmUsingDB("data")
  641. tableName := GetEdbDataTableName(source, subSource)
  642. if source == utils.DATA_SOURCE_PREDICT {
  643. tableName = "edb_data_predict_base"
  644. }
  645. sql := ` SELECT * FROM %s WHERE 1=1 `
  646. sql = fmt.Sprintf(sql, tableName)
  647. if condition != "" {
  648. sql += condition
  649. }
  650. sql += ` ORDER BY data_time DESC `
  651. sql += ` LIMIT ?,? `
  652. var ormList []*EdbDataORM
  653. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&ormList)
  654. if err != nil {
  655. return
  656. }
  657. item = toEdbDataList(ormList)
  658. return
  659. }
  660. // [2025-zsh-时间类型修复-chenhan]
  661. func toEdbDataList(ormList []*EdbDataORM) (dataList []*EdbData) {
  662. if ormList == nil || len(ormList) == 0 {
  663. return
  664. }
  665. for _, item := range ormList {
  666. dataList = append(dataList, item.ToEdbData())
  667. }
  668. return
  669. }
  670. // GetAllEdbDataListByCondition 根据条件获取所有的数据
  671. func GetAllEdbDataListByCondition(condition string, pars []interface{}, source, subSource int) (item []*EdbData, err error) {
  672. itemsOrm := make([]*EdbDataOrm, 0)
  673. o := orm.NewOrmUsingDB("data")
  674. tableName := GetEdbDataTableName(source, subSource)
  675. sql := ` SELECT * FROM %s WHERE 1=1 `
  676. sql = fmt.Sprintf(sql, tableName)
  677. if condition != "" {
  678. sql += condition
  679. }
  680. sql += ` ORDER BY data_time DESC `
  681. _, err = o.Raw(sql, pars).QueryRows(&itemsOrm)
  682. if err != nil {
  683. return
  684. }
  685. for _, v := range itemsOrm {
  686. dataItem := new(EdbData)
  687. dataItem.EdbDataId = v.EdbDataId
  688. dataItem.EdbInfoId = v.EdbInfoId
  689. dataItem.DataTime = v.DataTime.Format(utils.FormatDate)
  690. dataItem.Value = v.Value
  691. item = append(item, dataItem)
  692. }
  693. return
  694. }
  695. func GetEdbInfoByNewest() (item *EdbInfoList, err error) {
  696. o := orm.NewOrmUsingDB("data")
  697. var ormItem *EdbInfoOrm
  698. sql := ` SELECT * FROM edb_info WHERE 1=1 ORDER BY modify_time DESC LIMIT 1 `
  699. err = o.Raw(sql).QueryRow(&ormItem)
  700. if err != nil {
  701. return
  702. }
  703. item = ormItem.ToList()
  704. return
  705. }
  706. func ModifyEdbInfoModifyTime(edbInfoId int64) (err error) {
  707. o := orm.NewOrmUsingDB("data")
  708. sql := ` UPDATE edb_info SET modify_time = NOW() WHERE edb_info_id = ? `
  709. _, err = o.Raw(sql, edbInfoId).Exec()
  710. return
  711. }
  712. type MoveEdbInfoReq struct {
  713. EdbInfoId int `description:"指标ID"`
  714. PrevEdbInfoId int `description:"上一个指标ID"`
  715. NextEdbInfoId int `description:"下一个指标ID"`
  716. ClassifyId int `description:"分类id"`
  717. }
  718. func MoveEdbInfo(edbInfoId, classifyId int) (err error) {
  719. o := orm.NewOrmUsingDB("data")
  720. sql := ` UPDATE edb_info
  721. SET
  722. classify_id = ?
  723. WHERE edb_info_id = ?`
  724. _, err = o.Raw(sql, classifyId, edbInfoId).Exec()
  725. return
  726. }
  727. // GetEdbInfoByName 根据名称获取普通的指标
  728. func GetEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
  729. var ormList []*EdbInfoOrm
  730. items = make([]*EdbInfoList, 0)
  731. o := orm.NewOrmUsingDB("data")
  732. sql := ` SELECT * FROM edb_info WHERE edb_name=? AND edb_info_type = 0 `
  733. _, err = o.Raw(sql, edbName).QueryRows(&ormList)
  734. if err != nil {
  735. return
  736. }
  737. for _, ormItem := range ormList {
  738. items = append(items, ormItem.ToList())
  739. }
  740. return
  741. }
  742. // GetPredictEdbInfoByName 根据指标名称获取预测指标
  743. func GetPredictEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
  744. var ormList []*EdbInfoOrm
  745. items = make([]*EdbInfoList, 0)
  746. o := orm.NewOrmUsingDB("data")
  747. sql := ` SELECT * FROM edb_info WHERE edb_name=? AND edb_info_type = 1 `
  748. _, err = o.Raw(sql, edbName).QueryRows(&ormList)
  749. if err != nil {
  750. return
  751. }
  752. for _, ormItem := range ormList {
  753. items = append(items, ormItem.ToList())
  754. }
  755. return
  756. }
  757. func GetEdbInfoByEnName(edbNameEn string) (items []*EdbInfoList, err error) {
  758. var ormList []*EdbInfoOrm
  759. items = make([]*EdbInfoList, 0)
  760. o := orm.NewOrmUsingDB("data")
  761. sql := ` SELECT * FROM edb_info WHERE edb_name_en=? AND edb_info_type = 0 `
  762. _, err = o.Raw(sql, edbNameEn).QueryRows(&ormList)
  763. if err != nil {
  764. return
  765. }
  766. for _, ormItem := range ormList {
  767. items = append(items, ormItem.ToList())
  768. }
  769. return
  770. }
  771. func ModifyEdbInfoNameSource(edbNameSource string, edbInfoId int) (err error) {
  772. o := orm.NewOrmUsingDB("data")
  773. sql := ` UPDATE edb_info SET edb_name_source=? WHERE edb_info_id = ? `
  774. _, err = o.Raw(sql, edbNameSource, edbInfoId).Exec()
  775. return
  776. }
  777. func GetChartEdbMappingCount(edbInfoId int) (count int, err error) {
  778. o := orm.NewOrmUsingDB("data")
  779. sql := ` SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE edb_info_id=? `
  780. err = o.Raw(sql, edbInfoId).QueryRow(&count)
  781. return
  782. }
  783. type ChartEdbInfo struct {
  784. EdbInfoId int `description:"指标id"`
  785. EdbName string `description:"指标名称"`
  786. SourceName string `json:"-"`
  787. EdbNameAlias string `json:"-" description:"指标名称,别名"`
  788. }
  789. func EdbInfoSearchByKeyWord(keyword string) (searchList []*ChartEdbInfo, err error) {
  790. pars := make([]interface{}, 0)
  791. o := orm.NewOrmUsingDB("data")
  792. sql := ` SELECT edb_info_id,edb_name,source_name FROM edb_info WHERE 1=1 AND edb_info_type = 0 `
  793. if keyword != "" {
  794. sql += ` AND (edb_name LIKE ? OR edb_code LIKE ? ) `
  795. pars = append(pars, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword))
  796. }
  797. sql += ` ORDER BY create_time DESC `
  798. _, err = o.Raw(sql, pars...).QueryRows(&searchList)
  799. return
  800. }
  801. type EdbInfoMaxAndMinInfo struct {
  802. MinDate string `description:"最小日期"`
  803. MaxDate string `description:"最大日期"`
  804. MinValue float64 `description:"最小值"`
  805. MaxValue float64 `description:"最大值"`
  806. LatestValue float64 `description:"最新值"`
  807. }
  808. // [2025-zsh-时间类型修复-chenhan] 数据库获取
  809. type EdbInfoMaxAndMinInfoOrm struct {
  810. MinDate time.Time `description:"最小日期"`
  811. MaxDate time.Time `description:"最大日期"`
  812. MinValue float64 `description:"最小值"`
  813. MaxValue float64 `description:"最大值"`
  814. LatestValue float64 `description:"最新值"`
  815. }
  816. func (m *EdbInfoMaxAndMinInfoOrm) toEdbInfoMaxAndMinInfo() *EdbInfoMaxAndMinInfo {
  817. return &EdbInfoMaxAndMinInfo{
  818. MinDate: m.MinDate.Format(utils.FormatDate),
  819. MaxDate: m.MaxDate.Format(utils.FormatDate),
  820. MinValue: m.MinValue,
  821. MaxValue: m.MaxValue,
  822. LatestValue: m.LatestValue,
  823. }
  824. }
  825. // GetEdbInfoMaxAndMinInfo
  826. // @Description: 获取指标最大最小值
  827. // @author: Roc
  828. // @datetime 2024-05-07 15:34:00
  829. // @param source int
  830. // @param subSource int
  831. // @param edbCode string
  832. // @return item *EdbInfoMaxAndMinInfo
  833. // @return err error
  834. func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  835. // 自有数据需要额外处理(从mongo获取)
  836. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  837. return GetEdbInfoMaxAndMinInfoByMongo(source, subSource, edbCode)
  838. }
  839. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  840. return GetThsHfEdbInfoMaxAndMinInfoByMongo(source, subSource, edbCode)
  841. }
  842. // 默认走mysql
  843. return GetEdbInfoMaxAndMinInfoByMysql(source, subSource, edbCode)
  844. }
  845. // GetEdbInfoMaxAndMinInfoByMysql
  846. // @Description: 从mysql中获取指标最大最小值
  847. // @author: Roc
  848. // @datetime 2024-05-07 15:33:43
  849. // @param source int
  850. // @param subSource int
  851. // @param edbCode string
  852. // @return item *EdbInfoMaxAndMinInfo
  853. // @return err error
  854. func GetEdbInfoMaxAndMinInfoByMysql(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  855. o := orm.NewOrmUsingDB("data")
  856. sql := ``
  857. tableName := GetEdbDataTableName(source, subSource)
  858. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
  859. sql = fmt.Sprintf(sql, tableName)
  860. var ormItem *EdbInfoMaxAndMinInfoOrm
  861. err = o.Raw(sql, edbCode).QueryRow(&ormItem)
  862. if err != nil {
  863. return
  864. }
  865. item = ormItem.toEdbInfoMaxAndMinInfo()
  866. var latest_value float64
  867. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  868. sql = fmt.Sprintf(sql, tableName)
  869. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  870. item.LatestValue = latest_value
  871. return
  872. }
  873. // GetEdbInfoMaxAndMinInfoByMongo
  874. // @Description: 从mongo中获取指标最大最小值
  875. // @author: Roc
  876. // @datetime 2024-05-07 15:33:53
  877. // @param source int
  878. // @param subSource int
  879. // @param edbCode string
  880. // @return item *EdbInfoMaxAndMinInfo
  881. // @return err error
  882. func GetEdbInfoMaxAndMinInfoByMongo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  883. mogDataObj := new(mgo.EdbDataBusiness)
  884. pipeline := []bson.M{
  885. {"$match": bson.M{"edb_code": edbCode}},
  886. {"$group": bson.M{
  887. "_id": nil,
  888. "min_date": bson.M{"$min": "$data_time"},
  889. "max_date": bson.M{"$max": "$data_time"},
  890. "min_value": bson.M{"$min": "$value"},
  891. "max_value": bson.M{"$max": "$value"},
  892. }},
  893. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  894. }
  895. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  896. if err != nil {
  897. fmt.Println("EdbDataBusiness getEdbDataBusinessList Err:" + err.Error())
  898. return
  899. }
  900. if !result.MaxDate.IsZero() {
  901. whereQuery := bson.M{"edb_code": edbCode, "data_time": result.MaxDate}
  902. selectParam := bson.D{{"value", 1}, {"_id", 0}}
  903. latestValue, tmpErr := mogDataObj.GetLatestValue(whereQuery, selectParam)
  904. if tmpErr != nil {
  905. err = tmpErr
  906. return
  907. }
  908. result.LatestValue = latestValue.Value
  909. result.EndValue = latestValue.Value
  910. }
  911. item = &EdbInfoMaxAndMinInfo{
  912. MinDate: result.MinDate.Format(utils.FormatDate),
  913. MaxDate: result.MaxDate.Format(utils.FormatDate),
  914. MinValue: result.MinValue,
  915. MaxValue: result.MaxValue,
  916. LatestValue: result.LatestValue,
  917. }
  918. return
  919. }
  920. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  921. o := orm.NewOrmUsingDB("data")
  922. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id=? `
  923. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
  924. return
  925. }
  926. func GetEdbInfoFilter(condition string, pars []interface{}) (items []*EdbInfoList, err error) {
  927. var ormList []*EdbInfoOrm
  928. items = make([]*EdbInfoList, 0)
  929. o := orm.NewOrmUsingDB("data")
  930. sql := ` SELECT * FROM edb_info WHERE 1=1 AND edb_info_type = 0 `
  931. if condition != "" {
  932. sql += condition
  933. }
  934. sql += ` ORDER BY create_time DESC `
  935. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  936. if err != nil {
  937. return
  938. }
  939. for _, ormItem := range ormList {
  940. items = append(items, ormItem.ToList())
  941. }
  942. return
  943. }
  944. type AddEdbInfoResp struct {
  945. EdbInfoId int `description:"指标ID"`
  946. UniqueCode string `description:"指标唯一编码"`
  947. ClassifyId int `description:"分类id"`
  948. ExistEdbName []string `description:"重复指标名称"`
  949. }
  950. // GetEdbInfoCalculateListByCondition 获取指标关系列表
  951. func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
  952. o := orm.NewOrmUsingDB("data")
  953. //calculateTableName := GetEdbInfoCalculateTableName(source)
  954. //if calculateTableName == "" {
  955. // err = errors.New("无效的表名")
  956. // return
  957. //}
  958. sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
  959. //sql = fmt.Sprintf(sql, calculateTableName)
  960. if condition != "" {
  961. sql += condition
  962. }
  963. _, err = o.Raw(sql, pars).QueryRows(&items)
  964. return
  965. }
  966. // GetEdbInfoAllCalculateByEdbInfoIdList 根据指标id集合 获取基础指标对应的所有计算指标
  967. func GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  968. num := len(edbInfoIdList)
  969. if num <= 0 {
  970. return
  971. }
  972. var ormList []*EdbInfoOrm
  973. items = make([]*EdbInfo, 0)
  974. o := orm.NewOrmUsingDB("data")
  975. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  976. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  977. WHERE a.from_edb_info_id in (` + utils.GetOrmInReplace(num) + `)
  978. GROUP BY a.edb_info_id
  979. ORDER BY a.edb_info_id ASC `
  980. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&ormList)
  981. if err != nil {
  982. return
  983. }
  984. for _, ormItem := range ormList {
  985. items = append(items, ormItem.ToInfo())
  986. }
  987. return
  988. }
  989. func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  990. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  991. if err != nil && err.Error() != utils.ErrNoRow() {
  992. return
  993. }
  994. for _, item := range calculateList {
  995. if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤
  996. continue
  997. }
  998. if item.EdbType == 1 {
  999. baseEdbInfoArr = append(baseEdbInfoArr, item)
  1000. } else {
  1001. calculateInfoArr = append(calculateInfoArr, item)
  1002. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
  1003. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1004. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1005. }
  1006. }
  1007. return
  1008. }
  1009. func ModifyEdbInfoDataStatus(edbInfoId int64, source, subSource int, edbCode string) (err error) {
  1010. o := orm.NewOrmUsingDB("data")
  1011. sql := ``
  1012. tableName := GetEdbDataTableName(source, subSource)
  1013. sql = ` UPDATE %s SET edb_info_id=?,modify_time=NOW() WHERE edb_code=? `
  1014. sql = fmt.Sprintf(sql, tableName)
  1015. _, err = o.Raw(sql, edbInfoId, edbCode).Exec()
  1016. return
  1017. }
  1018. // GetFirstEdbInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  1019. func GetFirstEdbInfoByClassifyId(classifyId int) (item *EdbInfo, err error) {
  1020. var edbInfoOrm *EdbInfoOrm
  1021. o := orm.NewOrmUsingDB("data")
  1022. sql := ` SELECT * FROM edb_info WHERE classify_id=? order by sort asc,edb_info_id asc limit 1`
  1023. err = o.Raw(sql, classifyId).QueryRow(&item)
  1024. if err != nil {
  1025. return
  1026. }
  1027. item = edbInfoOrm.ToInfo()
  1028. return
  1029. }
  1030. // UpdateEdbInfoSortByClassifyId 根据分类id更新排序
  1031. func UpdateEdbInfoSortByClassifyId(classifyId, nowSort int, prevEdbInfoId int, updateSort string) (err error) {
  1032. o := orm.NewOrmUsingDB("data")
  1033. sql := ` update edb_info set sort = ` + updateSort + ` WHERE classify_id=?`
  1034. if prevEdbInfoId > 0 {
  1035. sql += ` AND ( sort > ? or ( edb_info_id > ` + fmt.Sprint(prevEdbInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` )) `
  1036. } else {
  1037. sql += ` AND ( sort > ? )`
  1038. }
  1039. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  1040. return
  1041. }
  1042. // Update 更新指标基础信息
  1043. func (edbInfo *EdbInfo) Update(cols []string) (err error) {
  1044. o := orm.NewOrmUsingDB("data")
  1045. _, err = o.Update(edbInfo, cols...)
  1046. return
  1047. }
  1048. type EdbInfoDataResp struct {
  1049. EdbInfo *EdbInfo
  1050. DataList []*EdbDataList
  1051. }
  1052. type EdbInfoDataFullClassifyResp struct {
  1053. EdbInfoExtItem *EdbInfoExt
  1054. EdbInfo *EdbInfoFullClassify
  1055. DataList []*EdbDataList
  1056. }
  1057. type EdbInfoReplaceReq struct {
  1058. OldEdbInfoId int `description:"原指标ID"`
  1059. NewEdbInfoId int `description:"替换为指标ID"`
  1060. }
  1061. // EdbInfoReplaceV2 替换指标v2版本(更换时间:2022年01月05日15:33:42)
  1062. //func EdbInfoReplaceV2(oldEdbInfo, newEdbInfo *EdbInfo, sysAdminId int, sysAdminRealName string) (mappingList,replaceChartTotal, replaceCalculateTotal int, err error) {
  1063. // defer func() {
  1064. // if err != nil {
  1065. // fmt.Println("ERR:", err.Error())
  1066. // }
  1067. // }()
  1068. //
  1069. // // 替换关联表中的source_edb_info_id
  1070. // mappingList, replaceChartTotal, replaceCalculateTotal, err := replaceChartEdb(oldEdbInfo, newEdbInfo)
  1071. // if err != nil {
  1072. // return
  1073. // }
  1074. // err = replaceRelationEdbInfo(mappingList, oldEdbInfo, newEdbInfo, sysAdminId, sysAdminRealName)
  1075. // return
  1076. //}
  1077. // ReplaceChartEdb 替换图表中的指标
  1078. func ReplaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (relationEdbInfoIdList []int, replaceChartTotal, replaceCalculateTotal int, err error) {
  1079. var errmsg string
  1080. relationEdbInfoIdList = make([]int, 0) // 关联的指标id
  1081. logMsg := `` // 记录替换的日志
  1082. o := orm.NewOrmUsingDB("data")
  1083. to, err := o.Begin()
  1084. if err != nil {
  1085. return
  1086. }
  1087. defer func() {
  1088. if err != nil {
  1089. _ = to.Rollback()
  1090. } else {
  1091. _ = to.Commit()
  1092. if logMsg != `` {
  1093. utils.FileLog.Info(fmt.Sprintf("替换指标记录,旧的指标id:%d,新的指标id:%d;%s", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, logMsg))
  1094. }
  1095. }
  1096. if errmsg != "" {
  1097. fmt.Println("errmsg:" + errmsg)
  1098. }
  1099. if err != nil && errmsg != "" {
  1100. go alarm_msg.SendAlarmMsg("替换图表中的指标失败提醒,errmsg:"+errmsg, 3)
  1101. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"替换指标失败提醒", "errmsg:"+errmsg, utils.EmailSendToUsers)
  1102. }
  1103. }()
  1104. //替换图表
  1105. {
  1106. chartEdbMappingList := make([]*ChartEdbInfoMapping, 0)
  1107. csql := `SELECT * FROM chart_edb_mapping WHERE edb_info_id=?`
  1108. _, err = to.Raw(csql, oldEdbInfo.EdbInfoId).QueryRows(&chartEdbMappingList)
  1109. if err != nil {
  1110. errmsg = "获取指标关联图表信息失败:Err:" + err.Error()
  1111. return
  1112. }
  1113. replaceChartTotal = len(chartEdbMappingList)
  1114. // 查询所有的相关的图表信息
  1115. chartInfoIds := make([]string, 0)
  1116. if len(chartEdbMappingList) > 0 {
  1117. for _, chartEdbMapping := range chartEdbMappingList {
  1118. chartInfoIds = append(chartInfoIds, strconv.Itoa(chartEdbMapping.ChartInfoId))
  1119. }
  1120. }
  1121. if len(chartInfoIds) > 0 {
  1122. chartInfoList, e := GetChartInfoListByChartIdList(chartInfoIds)
  1123. if e != nil {
  1124. err = e
  1125. errmsg = "获取图表信息失败:Err:" + e.Error()
  1126. return
  1127. }
  1128. for _, chartInfo := range chartInfoList {
  1129. updateStr := make([]string, 0)
  1130. if chartInfo.EdbInfoIds != "" && strings.Contains(chartInfo.EdbInfoIds, strconv.Itoa(oldEdbInfo.EdbInfoId)) {
  1131. //需要更换
  1132. //解析字符串
  1133. edbInfoIds := strings.Split(chartInfo.EdbInfoIds, ",")
  1134. for i, edbInfoId := range edbInfoIds {
  1135. if edbInfoId == strconv.Itoa(oldEdbInfo.EdbInfoId) {
  1136. edbInfoIds[i] = strconv.Itoa(newEdbInfo.EdbInfoId)
  1137. }
  1138. }
  1139. chartInfo.EdbInfoIds = strings.Join(edbInfoIds, ",")
  1140. updateStr = append(updateStr, "EdbInfoIds")
  1141. }
  1142. if chartInfo.ExtraConfig != "" || chartInfo.BarConfig != "" {
  1143. //判断是否是拟合方程或者散点图截面图
  1144. if chartInfo.Source == utils.CHART_SOURCE_FUTURE_GOOD {
  1145. // 商品价格曲线图的一些配置
  1146. var barConfig FutureGoodBarChartInfoReq
  1147. err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1148. if err != nil {
  1149. errmsg = "商品价格曲线图配置异常 json.Unmarshal:Err:" + err.Error()
  1150. return
  1151. }
  1152. if barConfig.BaseEdbInfoId == oldEdbInfo.EdbInfoId {
  1153. barConfig.BaseEdbInfoId = newEdbInfo.EdbInfoId
  1154. }
  1155. for k, item := range barConfig.EdbInfoIdList {
  1156. if item.EdbInfoId == oldEdbInfo.EdbInfoId && item.Source == 1 {
  1157. barConfig.EdbInfoIdList[k].EdbInfoId = newEdbInfo.EdbInfoId
  1158. }
  1159. }
  1160. // 更新图表配置信息
  1161. // 重新序列化
  1162. configJson, e := json.Marshal(barConfig)
  1163. if e != nil {
  1164. err = e
  1165. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1166. return
  1167. }
  1168. configStr := string(configJson)
  1169. chartInfo.BarConfig = configStr
  1170. updateStr = append(updateStr, "BarConfig")
  1171. } else if chartInfo.Source == utils.CHART_SOURCE_FUTURE_GOOD_PROFIT {
  1172. // 商品利润曲线图的一些配置
  1173. var extraConf FutureGoodProfitChartInfoReq
  1174. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConf)
  1175. if err != nil {
  1176. errmsg = "商品利润曲线图配置异常 json.Unmarshal:Err:" + err.Error()
  1177. return
  1178. }
  1179. if extraConf.BaseEdbInfoId == oldEdbInfo.EdbInfoId {
  1180. extraConf.BaseEdbInfoId = newEdbInfo.EdbInfoId
  1181. }
  1182. for k, v := range extraConf.EdbInfoIdList {
  1183. if v == oldEdbInfo.EdbInfoId {
  1184. extraConf.EdbInfoIdList[k] = newEdbInfo.EdbInfoId
  1185. }
  1186. }
  1187. // 更新图表配置信息
  1188. // 重新序列化
  1189. configJson, e := json.Marshal(extraConf)
  1190. if e != nil {
  1191. err = e
  1192. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1193. return
  1194. }
  1195. configStr := string(configJson)
  1196. chartInfo.ExtraConfig = configStr
  1197. updateStr = append(updateStr, "ExtraConfig")
  1198. } else if chartInfo.Source == utils.CHART_SOURCE_LINE_EQUATION {
  1199. //解析配置内容
  1200. var lineChartInfoConfig request.LineChartInfoReq
  1201. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  1202. if err != nil {
  1203. errmsg = "获取图表配置信息失败 json.Unmarshal:Err:" + err.Error()
  1204. return
  1205. }
  1206. xEdbInfoIdList := lineChartInfoConfig.XEdbInfoIdList
  1207. yEdbInfoIdList := lineChartInfoConfig.YEdbInfoIdList
  1208. if len(xEdbInfoIdList) > 0 {
  1209. // 循环判断是否存在
  1210. for k, xEdbInfoId := range xEdbInfoIdList {
  1211. if xEdbInfoId == oldEdbInfo.EdbInfoId {
  1212. xEdbInfoIdList[k] = newEdbInfo.EdbInfoId
  1213. }
  1214. }
  1215. }
  1216. if len(yEdbInfoIdList) > 0 {
  1217. // 循环判断是否存在
  1218. for k, yEdbInfoId := range yEdbInfoIdList {
  1219. if yEdbInfoId == oldEdbInfo.EdbInfoId {
  1220. yEdbInfoIdList[k] = newEdbInfo.EdbInfoId
  1221. }
  1222. }
  1223. }
  1224. // 替换新的指标信息
  1225. lineChartInfoConfig.XEdbInfoIdList = xEdbInfoIdList
  1226. lineChartInfoConfig.YEdbInfoIdList = yEdbInfoIdList
  1227. // 重新序列化
  1228. lineChartInfoConfigJson, e := json.Marshal(lineChartInfoConfig)
  1229. if e != nil {
  1230. err = e
  1231. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1232. return
  1233. }
  1234. lineChartInfoConfigStr := string(lineChartInfoConfigJson)
  1235. // 更新图表配置信息
  1236. chartInfo.ExtraConfig = lineChartInfoConfigStr
  1237. updateStr = append(updateStr, "ExtraConfig")
  1238. } else if chartInfo.ChartType == utils.CHART_TYPE_SECTION_SCATTER {
  1239. //解析配置内容
  1240. var tmpExtraConfig SectionScatterReq
  1241. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &tmpExtraConfig)
  1242. if err != nil {
  1243. errmsg = "获取截面散点图配置信息失败 json.Unmarshal:Err:" + err.Error()
  1244. return
  1245. }
  1246. //找到指标信息,并替换
  1247. if len(tmpExtraConfig.SeriesList) > 0 {
  1248. for k1, series := range tmpExtraConfig.SeriesList {
  1249. for k2, item := range series.EdbInfoList {
  1250. if item.XEdbInfoId == oldEdbInfo.EdbInfoId {
  1251. tmpExtraConfig.SeriesList[k1].EdbInfoList[k2].XEdbInfoId = newEdbInfo.EdbInfoId
  1252. }
  1253. if item.YEdbInfoId == oldEdbInfo.EdbInfoId {
  1254. tmpExtraConfig.SeriesList[k1].EdbInfoList[k2].YEdbInfoId = newEdbInfo.EdbInfoId
  1255. }
  1256. }
  1257. }
  1258. }
  1259. // 重新序列化
  1260. sectionScatterConfigJson, e := json.Marshal(tmpExtraConfig)
  1261. if e != nil {
  1262. err = e
  1263. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1264. return
  1265. }
  1266. sectionScatterConfigStr := string(sectionScatterConfigJson)
  1267. // 更新图表配置信息
  1268. chartInfo.ExtraConfig = sectionScatterConfigStr
  1269. updateStr = append(updateStr, "ExtraConfig")
  1270. } else if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  1271. //解析配置内容
  1272. var tmpExtraConfig ChartSectionExtraConf
  1273. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &tmpExtraConfig)
  1274. if err != nil {
  1275. errmsg = "获取截面散点图配置信息失败 json.Unmarshal:Err:" + err.Error()
  1276. return
  1277. }
  1278. //找到指标信息,并替换
  1279. if len(tmpExtraConfig.DateConfList) > 0 {
  1280. for k1, item := range tmpExtraConfig.DateConfList {
  1281. if item.EdbInfoId > 0 && item.EdbInfoId == oldEdbInfo.EdbInfoId {
  1282. tmpExtraConfig.DateConfList[k1].EdbInfoId = newEdbInfo.EdbInfoId
  1283. }
  1284. }
  1285. }
  1286. // 重新序列化
  1287. configJson, e := json.Marshal(tmpExtraConfig)
  1288. if e != nil {
  1289. err = e
  1290. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1291. return
  1292. }
  1293. configStr := string(configJson)
  1294. // 更新图表配置信息
  1295. chartInfo.ExtraConfig = configStr
  1296. updateStr = append(updateStr, "ExtraConfig")
  1297. }
  1298. }
  1299. if len(updateStr) > 0 {
  1300. updateStr = append(updateStr, "ModifyTime")
  1301. chartInfo.ModifyTime = time.Now()
  1302. err = chartInfo.Update(updateStr)
  1303. if err != nil {
  1304. errmsg = "更新图表信息失败:chartInfo.Update Err: " + err.Error()
  1305. return
  1306. }
  1307. }
  1308. }
  1309. }
  1310. // 查询所有的图表信息
  1311. if len(chartEdbMappingList) > 0 {
  1312. chartInfoIdList := make([]string, 0)
  1313. for _, mv := range chartEdbMappingList {
  1314. //获取图表所有指标信息
  1315. chartEdbList := make([]*ChartEdbInfoMapping, 0)
  1316. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=?`
  1317. _, err = to.Raw(csql, mv.ChartInfoId).QueryRows(&chartEdbList)
  1318. if err != nil {
  1319. errmsg = "获取图表所有指标信息失败:Err:" + err.Error()
  1320. return
  1321. }
  1322. // 查询图表信息
  1323. var minData, maxData float64
  1324. minData = newEdbInfo.MinValue
  1325. maxData = newEdbInfo.MaxValue
  1326. for _, cv := range chartEdbList {
  1327. if mv.IsAxis == cv.IsAxis {
  1328. if minData > cv.MinData {
  1329. minData = cv.MinData
  1330. }
  1331. if maxData < cv.MaxData {
  1332. maxData = cv.MaxData
  1333. }
  1334. }
  1335. }
  1336. //修改图表关联指标
  1337. rsql := ` UPDATE chart_edb_mapping SET edb_info_id=?,max_data=?,min_data=?,modify_time=NOW() WHERE chart_edb_mapping_id=? `
  1338. _, err = to.Raw(rsql, newEdbInfo.EdbInfoId, maxData, minData, mv.ChartEdbMappingId).Exec()
  1339. if err != nil {
  1340. errmsg = "更新图库指标信息失败:Err:" + err.Error()
  1341. return
  1342. }
  1343. rsql = ` UPDATE chart_series_edb_mapping SET edb_info_id=? WHERE edb_info_id=? and chart_info_id=?`
  1344. _, err = to.Raw(rsql, newEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoType, mv.ChartInfoId).Exec()
  1345. if err != nil {
  1346. errmsg = "更新图库系列指标信息失败:Err:" + err.Error()
  1347. return
  1348. }
  1349. chartInfoIdList = append(chartInfoIdList, fmt.Sprint(mv.ChartInfoId))
  1350. }
  1351. logMsg += `涉及到的图表id:` + strings.Join(chartInfoIdList, ",") + ";"
  1352. }
  1353. }
  1354. //替换计算指标
  1355. {
  1356. //获取所有包含的计算指标
  1357. mappingList := make([]*EdbInfoCalculateMapping, 0)
  1358. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
  1359. _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&mappingList)
  1360. if err != nil {
  1361. errmsg = "获取计算指标关联基础指标信息失败:Err:" + err.Error()
  1362. return
  1363. }
  1364. replaceCalculateTotal = len(mappingList)
  1365. //计算指标
  1366. if len(mappingList) > 0 {
  1367. edbInfoIdList := make([]string, 0)
  1368. for _, mv := range mappingList {
  1369. //如果即将替换的指标与当前指标id一致,那么就退出当前循环,进入下一循环
  1370. if mv.EdbInfoId == newEdbInfo.EdbInfoId {
  1371. continue
  1372. }
  1373. //替换原指标
  1374. msql := `UPDATE edb_info_calculate_mapping SET from_edb_info_id=?,from_edb_code=?,from_edb_name=?,from_source=?,from_source_name=? WHERE edb_info_calculate_mapping_id=? `
  1375. _, err = to.Raw(msql, newEdbInfo.EdbInfoId, newEdbInfo.EdbCode, newEdbInfo.EdbName, newEdbInfo.Source, newEdbInfo.SourceName, mv.EdbInfoCalculateMappingId).Exec()
  1376. if err != nil {
  1377. return
  1378. }
  1379. relationEdbInfoIdList = append(relationEdbInfoIdList, mv.EdbInfoId)
  1380. edbInfoIdList = append(edbInfoIdList, fmt.Sprint(mv.EdbInfoId))
  1381. }
  1382. logMsg += `涉及到的指标id:` + strings.Join(edbInfoIdList, ",") + ";"
  1383. }
  1384. }
  1385. // 替换预测指标中的来源指标
  1386. {
  1387. //获取所有包含的计算指标
  1388. predictEdbConfList := make([]*PredictEdbConf, 0)
  1389. msql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? GROUP BY predict_edb_info_id `
  1390. _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&predictEdbConfList)
  1391. if err != nil {
  1392. errmsg = "获取关联的预测指标信息失败:Err:" + err.Error()
  1393. return
  1394. }
  1395. replaceCalculateTotal += len(predictEdbConfList)
  1396. //替换预测指标的来源指标
  1397. msql = `UPDATE predict_edb_conf SET source_edb_info_id=? WHERE source_edb_info_id=? `
  1398. _, err = to.Raw(msql, newEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoId).Exec()
  1399. if err != nil {
  1400. return
  1401. }
  1402. if len(predictEdbConfList) > 0 {
  1403. edbInfoIdList := make([]string, 0)
  1404. for _, v := range predictEdbConfList {
  1405. relationEdbInfoIdList = append(relationEdbInfoIdList, v.PredictEdbInfoId)
  1406. edbInfoIdList = append(edbInfoIdList, fmt.Sprint(v.PredictEdbInfoId))
  1407. }
  1408. logMsg += `涉及到的预测指标id:` + strings.Join(edbInfoIdList, ",") + ";"
  1409. }
  1410. }
  1411. return
  1412. }
  1413. type EdbInfoView struct {
  1414. EdbInfoId int `orm:"column(edb_info_id);pk"`
  1415. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  1416. SourceName string `description:"来源名称"`
  1417. Source int `description:"来源id"`
  1418. EdbCode string `description:"指标编码"`
  1419. EdbName string `description:"指标名称"`
  1420. EdbNameSource string `description:"指标名称来源"`
  1421. Frequency string `description:"频率"`
  1422. Unit string `description:"单位"`
  1423. StartDate string `description:"起始日期"`
  1424. EndDate string `description:"终止日期"`
  1425. ClassifyId int `description:"分类id"`
  1426. SysUserId int
  1427. SysUserRealName string
  1428. UniqueCode string `description:"指标唯一编码"`
  1429. CreateTime string
  1430. ModifyTime string
  1431. MinValue float64 `description:"指标最小值"`
  1432. MaxValue float64 `description:"指标最大值"`
  1433. CalculateFormula string `description:"计算公式"`
  1434. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  1435. Sort int `description:"排序字段"`
  1436. IsUpdate int `description:"当天是否已更新,1:未更新,2:已更新"`
  1437. LatestDate string `description:"数据最新日期(实际日期)"`
  1438. LatestValue float64 `description:"数据最新值(实际值)"`
  1439. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  1440. SubSourceName string `description:"子数据来源名称"`
  1441. IndicatorCode string `description:"指标代码"`
  1442. StockCode string `description:"证券代码"`
  1443. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  1444. }
  1445. // 获取指标的所有计算指标,以及计算指标所依赖计算指标
  1446. func GetAllCalculateByEdbInfoId(edbInfoId int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1447. o := orm.NewOrmUsingDB("data")
  1448. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
  1449. _, err = o.Raw(msql, edbInfoId).QueryRows(&mappingList)
  1450. if err != nil {
  1451. return
  1452. }
  1453. return
  1454. }
  1455. // 获取指标的所有计算指标,以及计算指标所依赖计算指标
  1456. func GetAllCalculateByEdbInfoIds(edbInfoIds []int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1457. o := orm.NewOrmUsingDB("data")
  1458. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) GROUP BY edb_info_id `
  1459. _, err = o.Raw(msql, edbInfoIds).QueryRows(&mappingList)
  1460. if err != nil {
  1461. return
  1462. }
  1463. return
  1464. }
  1465. func GetAllCalculate(edbInfoId int, edbInfoMap map[int]int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1466. calculateList, err := GetAllCalculateByEdbInfoId(edbInfoId)
  1467. if err != nil && err.Error() != utils.ErrNoRow() {
  1468. return
  1469. }
  1470. for _, item := range calculateList {
  1471. _, ok := edbInfoMap[item.EdbInfoId]
  1472. if !ok {
  1473. edbInfoMap[item.EdbInfoId] = item.EdbInfoId
  1474. mappingList = append(mappingList, item)
  1475. newCalculateInfoArr, _ := GetAllCalculate(item.EdbInfoId, edbInfoMap)
  1476. mappingList = append(mappingList, newCalculateInfoArr...)
  1477. }
  1478. }
  1479. return
  1480. }
  1481. // GetAllCalculateByEdbInfoIdV2 获取计算指标的所有所依赖的指标(基础指标+计算指标)
  1482. func GetAllCalculateByEdbInfoIdV2(edbInfoId int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1483. o := orm.NewOrmUsingDB("data")
  1484. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE edb_info_id=? GROUP BY from_edb_info_id `
  1485. _, err = o.Raw(msql, edbInfoId).QueryRows(&mappingList)
  1486. if err != nil {
  1487. return
  1488. }
  1489. return
  1490. }
  1491. // GetAllCalculateV2 获取所有的指标(如果下层指标包含了待替换指标,那么就不加入)
  1492. func GetAllCalculateV2(oldEdbInfoId, replaceEdbInfoId int, edbInfoMap map[int]int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1493. calculateList, err := GetAllCalculateByEdbInfoId(oldEdbInfoId)
  1494. if err != nil && err.Error() != utils.ErrNoRow() {
  1495. return
  1496. }
  1497. tmpMappingList := make([]*EdbInfoCalculateMapping, 0)
  1498. for _, item := range calculateList {
  1499. //如果计算指标里面存在即将替换的指标id,那么退出当前循环,进入下一循环
  1500. if item.EdbInfoId == replaceEdbInfoId {
  1501. err = fmt.Errorf("指标重复1")
  1502. return
  1503. }
  1504. //获取该指标的依赖指标列表,如果依赖指标列表中存在即将替换的指标,那么过滤该指标
  1505. childCalculateList, tmpErr := GetAllCalculateByEdbInfoIdV2(item.EdbInfoId)
  1506. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1507. err = tmpErr
  1508. return
  1509. }
  1510. for _, childCalculate := range childCalculateList {
  1511. if childCalculate.FromEdbInfoId == replaceEdbInfoId {
  1512. err = fmt.Errorf("指标重复2")
  1513. return
  1514. }
  1515. }
  1516. _, ok := edbInfoMap[item.EdbInfoId]
  1517. if !ok {
  1518. edbInfoMap[item.EdbInfoId] = item.EdbInfoId
  1519. newCalculateInfoArr, tmpErr := GetAllCalculateV2(item.EdbInfoId, replaceEdbInfoId, edbInfoMap)
  1520. if tmpErr != nil {
  1521. err = tmpErr
  1522. continue
  1523. } else {
  1524. mappingList = append(mappingList, item)
  1525. tmpMappingList = append(tmpMappingList, newCalculateInfoArr...)
  1526. }
  1527. }
  1528. }
  1529. mappingList = append(mappingList, tmpMappingList...)
  1530. return
  1531. }
  1532. // EdbInfoFilterDataResp 搜索指标列表数据返回
  1533. type EdbInfoFilterDataResp struct {
  1534. Paging *paging.PagingItem
  1535. List []*EdbInfoList
  1536. }
  1537. // GetEdbInfoFilterList 获取指指标列表数据接口
  1538. func GetEdbInfoFilterList(condition string, pars []interface{}, startSize, pageSize int) (total int64, items []*EdbInfoList, err error) {
  1539. o := orm.NewOrmUsingDB("data")
  1540. sql := ` SELECT count(1) total FROM edb_info where 1=1 ` + condition + ` ORDER BY edb_info_id DESC `
  1541. err = o.Raw(sql, pars).QueryRow(&total)
  1542. if err != nil {
  1543. return
  1544. }
  1545. var ormList []*EdbInfoOrm
  1546. items = make([]*EdbInfoList, 0)
  1547. sql = ` SELECT * FROM edb_info where 1=1 ` + condition + ` ORDER BY edb_info_id DESC LIMIT ?,? `
  1548. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&ormList)
  1549. if err != nil {
  1550. return
  1551. }
  1552. for _, ormItem := range ormList {
  1553. items = append(items, ormItem.ToList())
  1554. }
  1555. return
  1556. }
  1557. // SetEdbInfoImageReq 设置指标图片
  1558. type SetEdbInfoImageReq struct {
  1559. EdbInfoId int `description:"指标ID"`
  1560. ImageUrl string `description:"指标图片地址"`
  1561. }
  1562. // GetNextEdbInfoByCondition 根据条件获取下一个指标
  1563. func GetNextEdbInfoByCondition(condition string, pars []interface{}) (item *EdbInfo, err error) {
  1564. var edbInfoOrm *EdbInfoOrm
  1565. o := orm.NewOrmUsingDB("data")
  1566. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1567. if condition != "" {
  1568. sql += condition
  1569. }
  1570. sql += " ORDER BY sort asc , edb_info_id asc LIMIT 1 "
  1571. err = o.Raw(sql, pars).QueryRow(&edbInfoOrm)
  1572. if err != nil {
  1573. return
  1574. }
  1575. item = edbInfoOrm.ToInfo()
  1576. return
  1577. }
  1578. // GetNextEdbInfo 根据分类id获取下一个 指标
  1579. func GetNextEdbInfo(classifyId, classifySort, classifyType, edbInfoType int) (item *EdbInfo, err error) {
  1580. var edbInfoOrm *EdbInfoOrm
  1581. o := orm.NewOrmUsingDB("data")
  1582. sql := ` SELECT b.* FROM edb_classify AS a
  1583. INNER JOIN edb_info AS b ON a.classify_id=b.classify_id
  1584. WHERE (a.sort>? OR (a.sort=? and a.classify_id>?) )
  1585. AND a.classify_type=? AND b.edb_info_type=?
  1586. ORDER BY a.sort ASC,b.sort asc,b.edb_info_id asc
  1587. LIMIT 1 `
  1588. err = o.Raw(sql, classifySort, classifySort, classifyId, classifyType, edbInfoType).QueryRow(&edbInfoOrm)
  1589. if err != nil {
  1590. return
  1591. }
  1592. item = edbInfoOrm.ToInfo()
  1593. return
  1594. }
  1595. // GetEdbInfoByEdbCodeList 根据指标code集合获取指标列表
  1596. func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo, err error) {
  1597. num := len(edbCodeList)
  1598. if num <= 0 {
  1599. return
  1600. }
  1601. var ormList []*EdbInfoOrm
  1602. items = make([]*EdbInfo, 0)
  1603. o := orm.NewOrmUsingDB("data")
  1604. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) `
  1605. _, err = o.Raw(sql, source, edbCodeList).QueryRows(&ormList)
  1606. if err != nil {
  1607. return
  1608. }
  1609. for _, ormItem := range ormList {
  1610. items = append(items, ormItem.ToInfo())
  1611. }
  1612. return
  1613. }
  1614. // GetEdbInfoByConditionCount 根据条件获取指标列表数据总数
  1615. func GetEdbInfoByConditionCount(condition string, pars []interface{}) (count int, err error) {
  1616. o := orm.NewOrmUsingDB("data")
  1617. sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
  1618. if condition != "" {
  1619. sql += condition
  1620. }
  1621. err = o.Raw(sql, pars).QueryRow(&count)
  1622. return
  1623. }
  1624. // GetEdbInfoListByCondition 根据条件获取指标列表数据
  1625. func GetEdbInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int, orderDesc string) (items []*EdbInfoList, err error) {
  1626. var ormList []*EdbInfoOrm
  1627. items = make([]*EdbInfoList, 0)
  1628. o := orm.NewOrmUsingDB("data")
  1629. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1630. if condition != "" {
  1631. sql += condition
  1632. }
  1633. if orderDesc == `` {
  1634. orderDesc = ` ASC `
  1635. }
  1636. sql += ` ORDER BY edb_info_id `
  1637. sql += orderDesc
  1638. if pageSize > 0 {
  1639. sql += ` LIMIT ?,? `
  1640. pars = append(pars, startSize, pageSize)
  1641. }
  1642. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  1643. if err != nil {
  1644. return
  1645. }
  1646. for _, ormItem := range ormList {
  1647. items = append(items, ormItem.ToList())
  1648. }
  1649. return
  1650. }
  1651. // GetEdbInfoListV2ByCondition 根据条件获取指标列表数据(EdbInfo原始数据结构)
  1652. func GetEdbInfoListV2ByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfo, err error) {
  1653. var ormList []*EdbInfoOrm
  1654. items = make([]*EdbInfo, 0)
  1655. o := orm.NewOrmUsingDB("data")
  1656. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1657. if condition != "" {
  1658. sql += condition
  1659. }
  1660. sql += ` ORDER BY edb_info_id ASC LIMIT ?,? `
  1661. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&ormList)
  1662. if err != nil {
  1663. return
  1664. }
  1665. for _, ormItem := range ormList {
  1666. items = append(items, ormItem.ToInfo())
  1667. }
  1668. return
  1669. }
  1670. // GetEdbInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1671. func GetEdbInfoListGroupByUserId(edbIdList []string) (items []*EdbInfo, err error) {
  1672. num := len(edbIdList)
  1673. if num <= 0 {
  1674. return
  1675. }
  1676. var ormList []*EdbInfoOrm
  1677. items = make([]*EdbInfo, 0)
  1678. o := orm.NewOrmUsingDB("data")
  1679. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  1680. _, err = o.Raw(sql, edbIdList).QueryRows(&ormList)
  1681. if err != nil {
  1682. return
  1683. }
  1684. for _, ormItem := range ormList {
  1685. items = append(items, ormItem.ToInfo())
  1686. }
  1687. return
  1688. }
  1689. // GetEdbInfoListByEdbInfoId
  1690. // @Description: 根据指标id列表获取列表信息
  1691. // @param edbIdList
  1692. // @return items
  1693. // @return err
  1694. func GetEdbInfoListByEdbInfoId(edbIdList []string) (items []*EdbInfo, err error) {
  1695. num := len(edbIdList)
  1696. if num <= 0 {
  1697. return
  1698. }
  1699. var ormList []*EdbInfoOrm
  1700. items = make([]*EdbInfo, 0)
  1701. o := orm.NewOrmUsingDB("data")
  1702. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1703. _, err = o.Raw(sql, edbIdList).QueryRows(&ormList)
  1704. if err != nil {
  1705. return
  1706. }
  1707. for _, ormItem := range ormList {
  1708. items = append(items, ormItem.ToInfo())
  1709. }
  1710. return
  1711. }
  1712. // GetEdbInfoListByUserId
  1713. // @Description: 根据指标id列表获取列表信息
  1714. // @param userIdList []int
  1715. // @param edbInfoType int
  1716. // @return items
  1717. // @return err
  1718. func GetEdbInfoListByUserId(userIdList []int, edbInfoType int) (items []*EdbInfo, err error) {
  1719. num := len(userIdList)
  1720. if num <= 0 {
  1721. return
  1722. }
  1723. var ormList []*EdbInfoOrm
  1724. items = make([]*EdbInfo, 0)
  1725. o := orm.NewOrmUsingDB("data")
  1726. sql := ` SELECT * FROM edb_info WHERE edb_info_type = ? AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1727. _, err = o.Raw(sql, edbInfoType, userIdList).QueryRows(&ormList)
  1728. if err != nil {
  1729. return
  1730. }
  1731. for _, ormItem := range ormList {
  1732. items = append(items, ormItem.ToInfo())
  1733. }
  1734. return
  1735. }
  1736. // ModifyEdbInfoUserIdByCodeList 根据指标code列表修改创建人
  1737. func ModifyEdbInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1738. num := len(edbIdList)
  1739. if num <= 0 {
  1740. return
  1741. }
  1742. o := orm.NewOrmUsingDB("data")
  1743. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1744. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  1745. return
  1746. }
  1747. // ModifyEdbInfoUserIdByOldUserId
  1748. // @Description: 根据旧用户id修改新用户id
  1749. // @author: Roc
  1750. // @datetime 2024-03-25 19:17:09
  1751. // @param edbIdList []string
  1752. // @param userId int
  1753. // @param userName string
  1754. // @return err error
  1755. func ModifyEdbInfoUserIdByOldUserId(oldUserIdList []int, edbInfoType, userId int, userName string) (err error) {
  1756. num := len(oldUserIdList)
  1757. if num <= 0 {
  1758. return
  1759. }
  1760. o := orm.NewOrmUsingDB("data")
  1761. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  1762. _, err = o.Raw(sql, userId, userName, oldUserIdList, edbInfoType).Exec()
  1763. return
  1764. }
  1765. // MoveEdbChartList 图表/指标信息
  1766. type MoveEdbChartList struct {
  1767. DataId string `description:"指标/图表唯一id"`
  1768. Code string `description:"指标code"`
  1769. Name string `description:"指标/图表名称"`
  1770. NameEn string `description:"指标/图表名称"`
  1771. ClassifyName string `description:"分类名称"`
  1772. ClassifyNameEn string `description:"分类名称"`
  1773. CreateUserId int `description:"创建人id"`
  1774. CreateUserName string `description:"创建人名称"`
  1775. }
  1776. // MoveEdbChartListResp 更改创建人返回数据
  1777. type MoveEdbChartListResp struct {
  1778. Paging *paging.PagingItem
  1779. List []MoveEdbChartList
  1780. }
  1781. type EdbChartClassifyResp struct {
  1782. List []*EdbChartClassify
  1783. }
  1784. type EdbChartClassify struct {
  1785. ClassifyId int
  1786. ClassifyName string
  1787. ParentId int
  1788. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1789. Child []*EdbChartClassify
  1790. }
  1791. // EdbInfoDataSeasonalResp 指标季节性数据返回
  1792. type EdbInfoDataSeasonalResp struct {
  1793. EdbInfo *EdbInfo
  1794. DataList interface{}
  1795. }
  1796. // SetEdbDataInsertConfigReq 设置插入规则的请求
  1797. type SetEdbDataInsertConfigReq struct {
  1798. EdbInfoId int `description:"指标ID"`
  1799. Date string `description:"日期"`
  1800. Value string `description:"值"`
  1801. }
  1802. // GetEdbInfoByClassifyId 用于分类展示
  1803. func GetEdbInfoByClassifyId(classifyId, edbInfoType, adminId int) (items []*EdbClassifyItems, err error) {
  1804. o := orm.NewOrmUsingDB("data")
  1805. sql := ` SELECT edb_info_id,classify_id,edb_name AS classify_name,edb_name_en AS classify_name_en,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type, sort,is_join_permission FROM edb_info WHERE classify_id = ? AND edb_info_type = ?`
  1806. pars := []interface{}{classifyId, edbInfoType}
  1807. // 如果筛选了用户id
  1808. if adminId > 0 {
  1809. sql += ` AND sys_user_id = ? `
  1810. pars = append(pars, adminId)
  1811. }
  1812. sql += ` order by sort asc,edb_info_id asc `
  1813. _, err = o.Raw(sql, pars).QueryRows(&items)
  1814. return
  1815. }
  1816. type EdbAndClassify struct {
  1817. EdbInfoId int `description:"指标id"`
  1818. EdbCode string `description:"指标code"`
  1819. UniqueCode string `description:"唯一code"`
  1820. EdbName string `description:"指标名称"`
  1821. ClassifyId int `description:"所属分类id"`
  1822. FirstClassifyId int `description:"第1级的分类id"`
  1823. FirstClassifyName string `description:"第1级的分类名称"`
  1824. SecondClassifyId int `description:"第2级的分类id"`
  1825. SecondClassifyName string `description:"第2级的分类名称"`
  1826. }
  1827. // GetEdbInfoAndClassifyListByEdbIdList 根据指标id列表获取 指标及分类信息
  1828. func GetEdbInfoAndClassifyListByEdbIdList(edbIdList []int) (items []*EdbAndClassify, err error) {
  1829. num := len(edbIdList)
  1830. if num <= 0 {
  1831. return
  1832. }
  1833. o := orm.NewOrmUsingDB("data")
  1834. sql := ` SELECT a.edb_info_id,a.edb_code,a.unique_code,a.edb_name,a.classify_id FROM edb_info AS a
  1835. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1836. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  1837. return
  1838. }
  1839. // TraceEdbInfoResp 指标追溯数据返回
  1840. type TraceEdbInfoResp struct {
  1841. EdbInfoId int `description:"指标id"`
  1842. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  1843. EdbName string `description:"指标名称"`
  1844. EdbNameEn string `description:"指标英文名称"`
  1845. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  1846. RuleTitle string `description:"指标规则"`
  1847. RuleTitleEn string `description:"指标规则(英文)"`
  1848. UniqueCode string `description:"唯一编码"`
  1849. ClassifyId int `description:"分类ID"`
  1850. Child []TraceEdbInfoResp `description:"下级来源"`
  1851. IsStop int8 `description:"是否终止"`
  1852. EdbInfo *EdbInfo `description:"指标信息" json:"-"`
  1853. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  1854. }
  1855. // BeforeAndAfterDateDataResp 前后几期数据
  1856. type BeforeAndAfterDateDataResp struct {
  1857. List []*EdbDataList `description:"list"`
  1858. Date string `description:"实际日期"`
  1859. ShowValue string `description:"展示值"`
  1860. }
  1861. // GetEdbInfoAdminList
  1862. func GetEdbInfoAdminList(edbType int) (list []int, err error) {
  1863. o := orm.NewOrmUsingDB("data")
  1864. sql := ` SELECT sys_user_id FROM edb_info WHERE edb_info_type = ? GROUP BY sys_user_id `
  1865. _, err = o.Raw(sql, edbType).QueryRows(&list)
  1866. return
  1867. }
  1868. type EdbInfoExistCheckResp struct {
  1869. IndexExist bool `description:"指标是否存在:true,存在,false:不存在"`
  1870. ExistStockCodeArr []string `description:"存在的证券代码"`
  1871. ExistEdbCodeArr []string `description:"存在的指标代码"`
  1872. ExistClassifyId []int `description:"存在的分类id"`
  1873. ExistIndexId []int `description:"存在的指标id"`
  1874. ExistEdbInfo []*EdbInfo `description:"存在的指标"`
  1875. }
  1876. type BatchAddEdbInfoReq struct {
  1877. BatchList []*BatchAddEdbInfo
  1878. }
  1879. type BatchAddEdbInfo struct {
  1880. Source int `description:"来源id"`
  1881. EdbName string `description:"指标名称"`
  1882. Frequency string `description:"频率"`
  1883. Unit string `description:"单位"`
  1884. ClassifyId int `description:"分类id"`
  1885. StockCode string `description:"证券代码"`
  1886. EdbCode string `description:"指标编码"`
  1887. ApiExtraPars string `description:"API额外参数"`
  1888. }
  1889. func GetEdbInfoWsdMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  1890. o := orm.NewOrmUsingDB("data")
  1891. sql := ``
  1892. tableName := GetEdbDataTableNameAndSubSource(source, subSource)
  1893. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
  1894. sql = fmt.Sprintf(sql, tableName)
  1895. err = o.Raw(sql, edbCode).QueryRow(&item)
  1896. if err != nil {
  1897. return
  1898. }
  1899. var latest_value float64
  1900. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  1901. sql = fmt.Sprintf(sql, tableName)
  1902. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  1903. item.LatestValue = latest_value
  1904. return
  1905. }
  1906. // GetEdbInfoByNames 根据名称获取普通的指标
  1907. func GetEdbInfoByNames(edbNames string) (items []*EdbInfoList, err error) {
  1908. var ormList []*EdbInfoOrm
  1909. items = make([]*EdbInfoList, 0)
  1910. o := orm.NewOrmUsingDB("data")
  1911. sql := ` SELECT * FROM edb_info WHERE edb_name IN (` + edbNames + `) AND edb_info_type = 0 `
  1912. _, err = o.Raw(sql).QueryRows(&ormList)
  1913. if err != nil {
  1914. return
  1915. }
  1916. for _, ormItem := range ormList {
  1917. items = append(items, ormItem.ToList())
  1918. }
  1919. return
  1920. }
  1921. func GetSmmEdbInfoMaxAndMinInfo(edbCodes []string) (item *EdbInfoMaxAndMinInfo, err error) {
  1922. o := orm.NewOrmUsingDB("data")
  1923. sql := ``
  1924. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM edb_data_ys WHERE edb_code IN (` + utils.GetOrmInReplace(len(edbCodes)) + `)`
  1925. err = o.Raw(sql, edbCodes).QueryRow(&item)
  1926. if err != nil {
  1927. return
  1928. }
  1929. var latest_value float64
  1930. sql = ` SELECT value AS latest_value FROM edb_data_ys WHERE edb_code IN (` + utils.GetOrmInReplace(len(edbCodes)) + `) ORDER BY data_time DESC LIMIT 1 `
  1931. err = o.Raw(sql, edbCodes).QueryRow(&latest_value)
  1932. item.LatestValue = latest_value
  1933. return
  1934. }
  1935. type EdbInfoSmmExistCheckResp struct {
  1936. EdbInfoExistCheckResp
  1937. ExistAll bool `description:"是否全部重复"`
  1938. }
  1939. // GetEdbBaseInfoList
  1940. // @Description: 获取指标库数据列表
  1941. // @author: Roc
  1942. // @datetime 2024-01-10 14:28:22
  1943. // @param condition string
  1944. // @param pars []interface{}
  1945. // @param orderBy string
  1946. // @param startSize int
  1947. // @param pageSize int
  1948. // @return total int
  1949. // @return items []*BaseRefreshEdbInfo
  1950. // @return err error
  1951. func GetEdbBaseInfoList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRefreshEdbInfo, err error) {
  1952. o := orm.NewOrmUsingDB("data")
  1953. // 数量汇总
  1954. totalSql := ` SELECT count(1) FROM edb_info WHERE 1=1 `
  1955. if condition != "" {
  1956. totalSql += condition
  1957. }
  1958. err = o.Raw(totalSql, pars).QueryRow(&total)
  1959. if err != nil {
  1960. return
  1961. }
  1962. // 列表数据
  1963. sql := ` SELECT edb_info_id as edb_info_id, classify_id as classify_id,edb_code as index_code,edb_name as index_name,end_date,end_value,sys_user_id,sys_user_real_name,frequency,no_update as is_stop,terminal_code FROM edb_info WHERE 1=1 `
  1964. if condition != "" {
  1965. sql += condition
  1966. }
  1967. if orderBy != "" {
  1968. sql += ` ORDER BY ` + orderBy
  1969. } else {
  1970. sql += ` ORDER BY edb_info_id ASC `
  1971. }
  1972. sql += ` LIMIT ?,? `
  1973. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1974. return
  1975. }
  1976. // ModifyEdbInfoUpdateStatus
  1977. // @Description: 修改指标库停更状态
  1978. // @author: Roc
  1979. // @datetime 2024-01-08 16:23:31
  1980. // @param edbIdList []int
  1981. // @param indexCodeList []string
  1982. // @param isStop int
  1983. // @return err error
  1984. func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int, calculateEdbInfoIds []int) (err error) {
  1985. idNum := len(edbIdList)
  1986. if idNum <= 0 {
  1987. return
  1988. }
  1989. o, err := orm.NewOrmUsingDB("data").Begin()
  1990. if err != nil {
  1991. return
  1992. }
  1993. defer func() {
  1994. if err != nil {
  1995. _ = o.Rollback()
  1996. return
  1997. }
  1998. _ = o.Commit()
  1999. }()
  2000. // 更改指标的更新状态
  2001. sql := ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  2002. _, err = o.Raw(sql, isStop, time.Now(), edbIdList).Exec()
  2003. if err != nil {
  2004. return
  2005. }
  2006. if len(calculateEdbInfoIds) > 0 {
  2007. // 批量更新相关联的指标ID
  2008. sql = ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  2009. _, err = o.Raw(sql, isStop, time.Now(), calculateEdbInfoIds).Exec()
  2010. if err != nil {
  2011. return
  2012. }
  2013. }
  2014. return
  2015. }
  2016. func GetEdbInfoCount(source int, edbCode string) (count int, err error) {
  2017. o := orm.NewOrmUsingDB("data")
  2018. sql := ` SELECT COUNT(1) AS count FROM edb_info
  2019. WHERE source=? AND edb_code = ?`
  2020. err = o.Raw(sql, source, edbCode).QueryRow(&count)
  2021. return
  2022. }
  2023. // GetEdbInfoByNameArr 根据名称获取指标
  2024. func GetEdbInfoByNameArr(names []string, edbInfoType int) (items []*EdbInfo, err error) {
  2025. if len(names) == 0 {
  2026. return
  2027. }
  2028. var ormList []*EdbInfoOrm
  2029. items = make([]*EdbInfo, 0)
  2030. o := orm.NewOrmUsingDB("data")
  2031. sql := fmt.Sprintf(`SELECT edb_info_id, edb_code, edb_name FROM edb_info WHERE edb_name IN (%s) AND edb_info_type = ? `, utils.GetOrmInReplace(len(names)))
  2032. _, err = o.Raw(sql, names, edbInfoType).QueryRows(&ormList)
  2033. if err != nil {
  2034. return
  2035. }
  2036. for _, ormItem := range ormList {
  2037. items = append(items, ormItem.ToInfo())
  2038. }
  2039. return
  2040. }
  2041. // GetEdbInfoByNameArr 根据指标编码获取指标
  2042. func GetEdbInfoByCodeArr(codes []string, edbInfoType int) (items []*EdbInfo, err error) {
  2043. if len(codes) == 0 {
  2044. return
  2045. }
  2046. var ormList []*EdbInfoOrm
  2047. items = make([]*EdbInfo, 0)
  2048. o := orm.NewOrmUsingDB("data")
  2049. sql := fmt.Sprintf(`SELECT edb_info_id, edb_code, edb_name FROM edb_info WHERE edb_code IN (%s) AND edb_info_type = ? `, utils.GetOrmInReplace(len(codes)))
  2050. _, err = o.Raw(sql, codes, edbInfoType).QueryRows(&ormList)
  2051. if err != nil {
  2052. return
  2053. }
  2054. for _, ormItem := range ormList {
  2055. items = append(items, ormItem.ToInfo())
  2056. }
  2057. return
  2058. }
  2059. // GetEdbCodesBySource 根据来源获取指标编码
  2060. func GetEdbCodesBySource(source int) (items []*EdbInfo, err error) {
  2061. var ormList []*EdbInfoOrm
  2062. items = make([]*EdbInfo, 0)
  2063. o := orm.NewOrmUsingDB("data")
  2064. sql := ` SELECT edb_info_id, edb_code, unique_code, classify_id FROM edb_info WHERE source = ? `
  2065. _, err = o.Raw(sql, source).QueryRows(&ormList)
  2066. if err != nil {
  2067. return
  2068. }
  2069. for _, ormItem := range ormList {
  2070. items = append(items, ormItem.ToInfo())
  2071. }
  2072. return
  2073. }
  2074. // GetAllEdbDataListData
  2075. // @Description: 获取指标的所有数据
  2076. // @author: Roc
  2077. // @datetime 2024-05-07 15:18:27
  2078. // @param edbInfoId int
  2079. // @param source int
  2080. // @param subSource int
  2081. // @param startDataTime string
  2082. // @return dataList []*EdbData
  2083. // @return err error
  2084. func GetAllEdbDataListData(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2085. // 自有数据需要额外处理(从mongo获取)
  2086. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  2087. return getAllDataByMongo(edbInfoId, source, subSource, startDataTime)
  2088. }
  2089. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  2090. return getThsHfAllDataByMongo(edbInfoId, source, subSource, startDataTime)
  2091. }
  2092. // 默认走mysql
  2093. return getAllDataByMysql(edbInfoId, source, subSource, startDataTime)
  2094. }
  2095. // getAllDataByMysql
  2096. // @Description: 从mysql获取指标的所有数据
  2097. // @author: Roc
  2098. // @datetime 2024-05-07 15:18:41
  2099. // @param edbInfoId int
  2100. // @param source int
  2101. // @param subSource int
  2102. // @param startDataTime string
  2103. // @return dataList []*data_manage.EdbData
  2104. // @return err error
  2105. func getAllDataByMysql(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2106. dataList = make([]*EdbData, 0)
  2107. var dataCondition string
  2108. var dataPars []interface{}
  2109. dataCondition += ` AND edb_info_id=? `
  2110. dataPars = append(dataPars, edbInfoId)
  2111. // 结束日期
  2112. if startDataTime != "" {
  2113. dataCondition += ` AND data_time > ? `
  2114. dataPars = append(dataPars, startDataTime)
  2115. }
  2116. // 获取列表数据
  2117. dataList, err = GetAllEdbDataListByCondition(dataCondition, dataPars, source, subSource)
  2118. if err != nil {
  2119. return
  2120. }
  2121. return
  2122. }
  2123. // getAllDataByMongo
  2124. // @Description: 从mongo获取指标的所有数据
  2125. // @author: Roc
  2126. // @datetime 2024-05-07 15:18:53
  2127. // @param edbInfoId int
  2128. // @param source int
  2129. // @param subSource int
  2130. // @param startDataTime string
  2131. // @return dataList []*data_manage.EdbData
  2132. // @return err error
  2133. func getAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2134. dataList = make([]*EdbData, 0)
  2135. mogDataObj := mgo.EdbDataBusiness{}
  2136. // 构建查询条件
  2137. queryConditions := bson.M{
  2138. "edb_info_id": edbInfoId,
  2139. }
  2140. // 开始日期
  2141. dateCondition, err := mgo.BuildDateCondition(startDataTime, "")
  2142. if err != nil {
  2143. return
  2144. }
  2145. if len(dateCondition) > 0 {
  2146. queryConditions["data_time"] = dateCondition
  2147. }
  2148. // 获取列表数据
  2149. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"-data_time"})
  2150. if tmpErr != nil {
  2151. err = tmpErr
  2152. return
  2153. }
  2154. for k, v := range tmpDataList {
  2155. dataList = append(dataList, &EdbData{
  2156. EdbDataId: k + 1,
  2157. EdbInfoId: v.EdbInfoId,
  2158. DataTime: v.DataTime.Format(utils.FormatDate),
  2159. Value: v.Value,
  2160. })
  2161. }
  2162. return
  2163. }
  2164. // GetEdbClassifyIdListBySource 获取普通指标的分类列表
  2165. func GetEdbClassifyIdListBySource(source int) (items []int, err error) {
  2166. o := orm.NewOrmUsingDB("data")
  2167. sql := `SELECT distinct classify_id FROM edb_info WHERE source = ? and edb_info_type=0`
  2168. _, err = o.Raw(sql, source).QueryRows(&items)
  2169. return
  2170. }
  2171. // GetEdbInfoByClassifyIdAndSource 用于分类展示
  2172. func GetEdbInfoByClassifyIdAndSource(classifyId, edbInfoType, source int) (items []*EdbClassifyItems, err error) {
  2173. o := orm.NewOrmUsingDB("data")
  2174. sql := ` SELECT edb_info_id,classify_id,edb_name AS classify_name,edb_name_en AS classify_name_en,unique_code,source_name,source,sys_user_id,sys_user_real_name,start_date,edb_code,edb_type, sort,is_join_permission FROM edb_info WHERE classify_id = ? AND edb_info_type = ? AND source =?`
  2175. pars := []interface{}{classifyId, edbInfoType, source}
  2176. sql += ` order by sort asc,edb_info_id asc `
  2177. _, err = o.Raw(sql, pars).QueryRows(&items)
  2178. return
  2179. }
  2180. type ReplaceEdbInfoItem struct {
  2181. OldEdbInfo *EdbInfo
  2182. NewEdbInfo *EdbInfo
  2183. }
  2184. type EdbInfoEditRecord struct {
  2185. EdbInfoId int `description:"指标ID"`
  2186. EdbName string `description:"指标名称"`
  2187. Frequency string `description:"频率"`
  2188. Unit string `description:"单位"`
  2189. ClassifyId int `description:"分类id"`
  2190. CalculateFormula string `description:"计算公式"`
  2191. OperateUserId int `description:"操作人id"`
  2192. OperateUserRealName string `description:"操作人姓名"`
  2193. }
  2194. func ModifyEdbInfoBaseTimeById(edbInfoId int, cTime time.Time) (err error) {
  2195. o := orm.NewOrmUsingDB("data")
  2196. // 更新修改时间
  2197. sql := ` UPDATE edb_info SET base_modify_time = ? WHERE edb_info_id = ? `
  2198. _, err = o.Raw(sql, cTime, edbInfoId).Exec()
  2199. return
  2200. }
  2201. func GetEdbInfoFieldList(cond string, pars []interface{}, fields []string) (items []*EdbInfo, err error) {
  2202. field := " * "
  2203. if len(fields) > 0 {
  2204. field = strings.Join(fields, ",")
  2205. }
  2206. var ormList []*EdbInfoOrm
  2207. items = make([]*EdbInfo, 0)
  2208. o := orm.NewOrmUsingDB("data")
  2209. sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s `, field, cond)
  2210. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  2211. if err != nil {
  2212. return
  2213. }
  2214. for _, ormItem := range ormList {
  2215. items = append(items, ormItem.ToInfo())
  2216. }
  2217. return
  2218. }
  2219. // EdbInfoExtra 指标额外数据-extra字段
  2220. type EdbInfoExtra struct {
  2221. ApiExtraPars string `description:"API-额外参数(如同花顺日期序列)"`
  2222. }
  2223. func GetEdbInfoListByCond(condition string, pars []interface{}) (items []*EdbInfoList, err error) {
  2224. var ormList []*EdbInfoOrm
  2225. items = make([]*EdbInfoList, 0)
  2226. o := orm.NewOrmUsingDB("data")
  2227. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  2228. if condition != "" {
  2229. sql += condition
  2230. }
  2231. sql += ` ORDER BY create_time DESC `
  2232. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  2233. if err != nil {
  2234. return
  2235. }
  2236. for _, ormItem := range ormList {
  2237. items = append(items, ormItem.ToList())
  2238. }
  2239. return
  2240. }
  2241. func GetThsHfEdbInfoMaxAndMinInfoByMongo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  2242. mogDataObj := new(mgo.EdbDataThsHf)
  2243. pipeline := []bson.M{
  2244. {"$match": bson.M{"edb_code": edbCode}},
  2245. {"$group": bson.M{
  2246. "_id": nil,
  2247. "min_date": bson.M{"$min": "$data_time"},
  2248. "max_date": bson.M{"$max": "$data_time"},
  2249. "min_value": bson.M{"$min": "$value"},
  2250. "max_value": bson.M{"$max": "$value"},
  2251. }},
  2252. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  2253. }
  2254. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  2255. if err != nil {
  2256. fmt.Println("EdbDataThsHf getEdbDataThsHfList Err:" + err.Error())
  2257. return
  2258. }
  2259. if !result.MaxDate.IsZero() {
  2260. whereQuery := bson.M{"edb_code": edbCode, "data_time": result.MaxDate}
  2261. selectParam := bson.D{{"value", 1}, {"_id", 0}}
  2262. latestValue, tmpErr := mogDataObj.GetLatestValue(whereQuery, selectParam)
  2263. if tmpErr != nil {
  2264. err = tmpErr
  2265. return
  2266. }
  2267. result.LatestValue = latestValue.Value
  2268. result.EndValue = latestValue.Value
  2269. }
  2270. item = &EdbInfoMaxAndMinInfo{
  2271. MinDate: result.MinDate.Format(utils.FormatDate),
  2272. MaxDate: result.MaxDate.Format(utils.FormatDate),
  2273. MinValue: result.MinValue,
  2274. MaxValue: result.MaxValue,
  2275. LatestValue: result.LatestValue,
  2276. }
  2277. return
  2278. }
  2279. func getThsHfAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2280. dataList = make([]*EdbData, 0)
  2281. mogDataObj := mgo.EdbDataThsHf{}
  2282. // 构建查询条件
  2283. queryConditions := bson.M{
  2284. "edb_info_id": edbInfoId,
  2285. }
  2286. // 开始日期
  2287. dateCondition, err := mgo.BuildDateCondition(startDataTime, "")
  2288. if err != nil {
  2289. return
  2290. }
  2291. if len(dateCondition) > 0 {
  2292. queryConditions["data_time"] = dateCondition
  2293. }
  2294. // 获取列表数据
  2295. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"-data_time"})
  2296. if tmpErr != nil {
  2297. err = tmpErr
  2298. return
  2299. }
  2300. for k, v := range tmpDataList {
  2301. dataList = append(dataList, &EdbData{
  2302. EdbDataId: k + 1,
  2303. EdbInfoId: v.EdbInfoId,
  2304. DataTime: v.DataTime.Format(utils.FormatDate),
  2305. Value: v.Value,
  2306. })
  2307. }
  2308. return
  2309. }
  2310. type EdbNameCheckResult struct {
  2311. EdbCode string
  2312. EdbName string
  2313. Exist bool
  2314. }
  2315. // UpdateEdbClassifyIdByChartInfoId
  2316. func UpdateEdbClassifyIdByChartInfoId(chartInfoIds []int, classifyId int) (err error) {
  2317. o := orm.NewOrmUsingDB("data")
  2318. sql := ` update edb_info set classify_id = ? WHERE edb_info_id in (` + utils.GetOrmInReplace(len(chartInfoIds)) + `) `
  2319. _, err = o.Raw(sql, classifyId, chartInfoIds).Exec()
  2320. return
  2321. }