edb_info.go 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553
  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. // GetEdbInfoMaxAndMinInfo
  809. // @Description: 获取指标最大最小值
  810. // @author: Roc
  811. // @datetime 2024-05-07 15:34:00
  812. // @param source int
  813. // @param subSource int
  814. // @param edbCode string
  815. // @return item *EdbInfoMaxAndMinInfo
  816. // @return err error
  817. func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  818. // 自有数据需要额外处理(从mongo获取)
  819. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  820. return GetEdbInfoMaxAndMinInfoByMongo(source, subSource, edbCode)
  821. }
  822. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  823. return GetThsHfEdbInfoMaxAndMinInfoByMongo(source, subSource, edbCode)
  824. }
  825. // 默认走mysql
  826. return GetEdbInfoMaxAndMinInfoByMysql(source, subSource, edbCode)
  827. }
  828. // GetEdbInfoMaxAndMinInfoByMysql
  829. // @Description: 从mysql中获取指标最大最小值
  830. // @author: Roc
  831. // @datetime 2024-05-07 15:33:43
  832. // @param source int
  833. // @param subSource int
  834. // @param edbCode string
  835. // @return item *EdbInfoMaxAndMinInfo
  836. // @return err error
  837. func GetEdbInfoMaxAndMinInfoByMysql(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  838. o := orm.NewOrmUsingDB("data")
  839. sql := ``
  840. tableName := GetEdbDataTableName(source, subSource)
  841. 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=? `
  842. sql = fmt.Sprintf(sql, tableName)
  843. err = o.Raw(sql, edbCode).QueryRow(&item)
  844. if err != nil {
  845. return
  846. }
  847. var latest_value float64
  848. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  849. sql = fmt.Sprintf(sql, tableName)
  850. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  851. item.LatestValue = latest_value
  852. return
  853. }
  854. // GetEdbInfoMaxAndMinInfoByMongo
  855. // @Description: 从mongo中获取指标最大最小值
  856. // @author: Roc
  857. // @datetime 2024-05-07 15:33:53
  858. // @param source int
  859. // @param subSource int
  860. // @param edbCode string
  861. // @return item *EdbInfoMaxAndMinInfo
  862. // @return err error
  863. func GetEdbInfoMaxAndMinInfoByMongo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  864. mogDataObj := new(mgo.EdbDataBusiness)
  865. pipeline := []bson.M{
  866. {"$match": bson.M{"edb_code": edbCode}},
  867. {"$group": bson.M{
  868. "_id": nil,
  869. "min_date": bson.M{"$min": "$data_time"},
  870. "max_date": bson.M{"$max": "$data_time"},
  871. "min_value": bson.M{"$min": "$value"},
  872. "max_value": bson.M{"$max": "$value"},
  873. }},
  874. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  875. }
  876. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  877. if err != nil {
  878. fmt.Println("EdbDataBusiness getEdbDataBusinessList Err:" + err.Error())
  879. return
  880. }
  881. if !result.MaxDate.IsZero() {
  882. whereQuery := bson.M{"edb_code": edbCode, "data_time": result.MaxDate}
  883. selectParam := bson.D{{"value", 1}, {"_id", 0}}
  884. latestValue, tmpErr := mogDataObj.GetLatestValue(whereQuery, selectParam)
  885. if tmpErr != nil {
  886. err = tmpErr
  887. return
  888. }
  889. result.LatestValue = latestValue.Value
  890. result.EndValue = latestValue.Value
  891. }
  892. item = &EdbInfoMaxAndMinInfo{
  893. MinDate: result.MinDate.Format(utils.FormatDate),
  894. MaxDate: result.MaxDate.Format(utils.FormatDate),
  895. MinValue: result.MinValue,
  896. MaxValue: result.MaxValue,
  897. LatestValue: result.LatestValue,
  898. }
  899. return
  900. }
  901. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  902. o := orm.NewOrmUsingDB("data")
  903. 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=? `
  904. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
  905. return
  906. }
  907. func GetEdbInfoFilter(condition string, pars []interface{}) (items []*EdbInfoList, err error) {
  908. var ormList []*EdbInfoOrm
  909. items = make([]*EdbInfoList, 0)
  910. o := orm.NewOrmUsingDB("data")
  911. sql := ` SELECT * FROM edb_info WHERE 1=1 AND edb_info_type = 0 `
  912. if condition != "" {
  913. sql += condition
  914. }
  915. sql += ` ORDER BY create_time DESC `
  916. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  917. if err != nil {
  918. return
  919. }
  920. for _, ormItem := range ormList {
  921. items = append(items, ormItem.ToList())
  922. }
  923. return
  924. }
  925. type AddEdbInfoResp struct {
  926. EdbInfoId int `description:"指标ID"`
  927. UniqueCode string `description:"指标唯一编码"`
  928. ClassifyId int `description:"分类id"`
  929. ExistEdbName []string `description:"重复指标名称"`
  930. }
  931. // GetEdbInfoCalculateListByCondition 获取指标关系列表
  932. func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
  933. o := orm.NewOrmUsingDB("data")
  934. //calculateTableName := GetEdbInfoCalculateTableName(source)
  935. //if calculateTableName == "" {
  936. // err = errors.New("无效的表名")
  937. // return
  938. //}
  939. sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
  940. //sql = fmt.Sprintf(sql, calculateTableName)
  941. if condition != "" {
  942. sql += condition
  943. }
  944. _, err = o.Raw(sql, pars).QueryRows(&items)
  945. return
  946. }
  947. // GetEdbInfoAllCalculateByEdbInfoIdList 根据指标id集合 获取基础指标对应的所有计算指标
  948. func GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  949. num := len(edbInfoIdList)
  950. if num <= 0 {
  951. return
  952. }
  953. var ormList []*EdbInfoOrm
  954. items = make([]*EdbInfo, 0)
  955. o := orm.NewOrmUsingDB("data")
  956. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  957. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  958. WHERE a.from_edb_info_id in (` + utils.GetOrmInReplace(num) + `)
  959. GROUP BY a.edb_info_id
  960. ORDER BY a.edb_info_id ASC `
  961. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&ormList)
  962. if err != nil {
  963. return
  964. }
  965. for _, ormItem := range ormList {
  966. items = append(items, ormItem.ToInfo())
  967. }
  968. return
  969. }
  970. func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  971. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  972. if err != nil && err.Error() != utils.ErrNoRow() {
  973. return
  974. }
  975. for _, item := range calculateList {
  976. if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤
  977. continue
  978. }
  979. if item.EdbType == 1 {
  980. baseEdbInfoArr = append(baseEdbInfoArr, item)
  981. } else {
  982. calculateInfoArr = append(calculateInfoArr, item)
  983. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
  984. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  985. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  986. }
  987. }
  988. return
  989. }
  990. func ModifyEdbInfoDataStatus(edbInfoId int64, source, subSource int, edbCode string) (err error) {
  991. o := orm.NewOrmUsingDB("data")
  992. sql := ``
  993. tableName := GetEdbDataTableName(source, subSource)
  994. sql = ` UPDATE %s SET edb_info_id=?,modify_time=NOW() WHERE edb_code=? `
  995. sql = fmt.Sprintf(sql, tableName)
  996. _, err = o.Raw(sql, edbInfoId, edbCode).Exec()
  997. return
  998. }
  999. // GetFirstEdbInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  1000. func GetFirstEdbInfoByClassifyId(classifyId int) (item *EdbInfo, err error) {
  1001. var edbInfoOrm *EdbInfoOrm
  1002. o := orm.NewOrmUsingDB("data")
  1003. sql := ` SELECT * FROM edb_info WHERE classify_id=? order by sort asc,edb_info_id asc limit 1`
  1004. err = o.Raw(sql, classifyId).QueryRow(&item)
  1005. if err != nil {
  1006. return
  1007. }
  1008. item = edbInfoOrm.ToInfo()
  1009. return
  1010. }
  1011. // UpdateEdbInfoSortByClassifyId 根据分类id更新排序
  1012. func UpdateEdbInfoSortByClassifyId(classifyId, nowSort int, prevEdbInfoId int, updateSort string) (err error) {
  1013. o := orm.NewOrmUsingDB("data")
  1014. sql := ` update edb_info set sort = ` + updateSort + ` WHERE classify_id=?`
  1015. if prevEdbInfoId > 0 {
  1016. sql += ` AND ( sort > ? or ( edb_info_id > ` + fmt.Sprint(prevEdbInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` )) `
  1017. } else {
  1018. sql += ` AND ( sort > ? )`
  1019. }
  1020. _, err = o.Raw(sql, classifyId, nowSort).Exec()
  1021. return
  1022. }
  1023. // Update 更新指标基础信息
  1024. func (edbInfo *EdbInfo) Update(cols []string) (err error) {
  1025. o := orm.NewOrmUsingDB("data")
  1026. _, err = o.Update(edbInfo, cols...)
  1027. return
  1028. }
  1029. type EdbInfoDataResp struct {
  1030. EdbInfo *EdbInfo
  1031. DataList []*EdbDataList
  1032. }
  1033. type EdbInfoDataFullClassifyResp struct {
  1034. EdbInfoExtItem *EdbInfoExt
  1035. EdbInfo *EdbInfoFullClassify
  1036. DataList []*EdbDataList
  1037. }
  1038. type EdbInfoReplaceReq struct {
  1039. OldEdbInfoId int `description:"原指标ID"`
  1040. NewEdbInfoId int `description:"替换为指标ID"`
  1041. }
  1042. // EdbInfoReplaceV2 替换指标v2版本(更换时间:2022年01月05日15:33:42)
  1043. //func EdbInfoReplaceV2(oldEdbInfo, newEdbInfo *EdbInfo, sysAdminId int, sysAdminRealName string) (mappingList,replaceChartTotal, replaceCalculateTotal int, err error) {
  1044. // defer func() {
  1045. // if err != nil {
  1046. // fmt.Println("ERR:", err.Error())
  1047. // }
  1048. // }()
  1049. //
  1050. // // 替换关联表中的source_edb_info_id
  1051. // mappingList, replaceChartTotal, replaceCalculateTotal, err := replaceChartEdb(oldEdbInfo, newEdbInfo)
  1052. // if err != nil {
  1053. // return
  1054. // }
  1055. // err = replaceRelationEdbInfo(mappingList, oldEdbInfo, newEdbInfo, sysAdminId, sysAdminRealName)
  1056. // return
  1057. //}
  1058. // ReplaceChartEdb 替换图表中的指标
  1059. func ReplaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (relationEdbInfoIdList []int, replaceChartTotal, replaceCalculateTotal int, err error) {
  1060. var errmsg string
  1061. relationEdbInfoIdList = make([]int, 0) // 关联的指标id
  1062. logMsg := `` // 记录替换的日志
  1063. o := orm.NewOrmUsingDB("data")
  1064. to, err := o.Begin()
  1065. if err != nil {
  1066. return
  1067. }
  1068. defer func() {
  1069. if err != nil {
  1070. _ = to.Rollback()
  1071. } else {
  1072. _ = to.Commit()
  1073. if logMsg != `` {
  1074. utils.FileLog.Info(fmt.Sprintf("替换指标记录,旧的指标id:%d,新的指标id:%d;%s", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, logMsg))
  1075. }
  1076. }
  1077. if errmsg != "" {
  1078. fmt.Println("errmsg:" + errmsg)
  1079. }
  1080. if err != nil && errmsg != "" {
  1081. go alarm_msg.SendAlarmMsg("替换图表中的指标失败提醒,errmsg:"+errmsg, 3)
  1082. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"替换指标失败提醒", "errmsg:"+errmsg, utils.EmailSendToUsers)
  1083. }
  1084. }()
  1085. //替换图表
  1086. {
  1087. chartEdbMappingList := make([]*ChartEdbInfoMapping, 0)
  1088. csql := `SELECT * FROM chart_edb_mapping WHERE edb_info_id=?`
  1089. _, err = to.Raw(csql, oldEdbInfo.EdbInfoId).QueryRows(&chartEdbMappingList)
  1090. if err != nil {
  1091. errmsg = "获取指标关联图表信息失败:Err:" + err.Error()
  1092. return
  1093. }
  1094. replaceChartTotal = len(chartEdbMappingList)
  1095. // 查询所有的相关的图表信息
  1096. chartInfoIds := make([]string, 0)
  1097. if len(chartEdbMappingList) > 0 {
  1098. for _, chartEdbMapping := range chartEdbMappingList {
  1099. chartInfoIds = append(chartInfoIds, strconv.Itoa(chartEdbMapping.ChartInfoId))
  1100. }
  1101. }
  1102. if len(chartInfoIds) > 0 {
  1103. chartInfoList, e := GetChartInfoListByChartIdList(chartInfoIds)
  1104. if e != nil {
  1105. err = e
  1106. errmsg = "获取图表信息失败:Err:" + e.Error()
  1107. return
  1108. }
  1109. for _, chartInfo := range chartInfoList {
  1110. updateStr := make([]string, 0)
  1111. if chartInfo.EdbInfoIds != "" && strings.Contains(chartInfo.EdbInfoIds, strconv.Itoa(oldEdbInfo.EdbInfoId)) {
  1112. //需要更换
  1113. //解析字符串
  1114. edbInfoIds := strings.Split(chartInfo.EdbInfoIds, ",")
  1115. for i, edbInfoId := range edbInfoIds {
  1116. if edbInfoId == strconv.Itoa(oldEdbInfo.EdbInfoId) {
  1117. edbInfoIds[i] = strconv.Itoa(newEdbInfo.EdbInfoId)
  1118. }
  1119. }
  1120. chartInfo.EdbInfoIds = strings.Join(edbInfoIds, ",")
  1121. updateStr = append(updateStr, "EdbInfoIds")
  1122. }
  1123. if chartInfo.ExtraConfig != "" || chartInfo.BarConfig != "" {
  1124. //判断是否是拟合方程或者散点图截面图
  1125. if chartInfo.Source == utils.CHART_SOURCE_FUTURE_GOOD {
  1126. // 商品价格曲线图的一些配置
  1127. var barConfig FutureGoodBarChartInfoReq
  1128. err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1129. if err != nil {
  1130. errmsg = "商品价格曲线图配置异常 json.Unmarshal:Err:" + err.Error()
  1131. return
  1132. }
  1133. if barConfig.BaseEdbInfoId == oldEdbInfo.EdbInfoId {
  1134. barConfig.BaseEdbInfoId = newEdbInfo.EdbInfoId
  1135. }
  1136. for k, item := range barConfig.EdbInfoIdList {
  1137. if item.EdbInfoId == oldEdbInfo.EdbInfoId && item.Source == 1 {
  1138. barConfig.EdbInfoIdList[k].EdbInfoId = newEdbInfo.EdbInfoId
  1139. }
  1140. }
  1141. // 更新图表配置信息
  1142. // 重新序列化
  1143. configJson, e := json.Marshal(barConfig)
  1144. if e != nil {
  1145. err = e
  1146. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1147. return
  1148. }
  1149. configStr := string(configJson)
  1150. chartInfo.BarConfig = configStr
  1151. updateStr = append(updateStr, "BarConfig")
  1152. } else if chartInfo.Source == utils.CHART_SOURCE_FUTURE_GOOD_PROFIT {
  1153. // 商品利润曲线图的一些配置
  1154. var extraConf FutureGoodProfitChartInfoReq
  1155. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConf)
  1156. if err != nil {
  1157. errmsg = "商品利润曲线图配置异常 json.Unmarshal:Err:" + err.Error()
  1158. return
  1159. }
  1160. if extraConf.BaseEdbInfoId == oldEdbInfo.EdbInfoId {
  1161. extraConf.BaseEdbInfoId = newEdbInfo.EdbInfoId
  1162. }
  1163. for k, v := range extraConf.EdbInfoIdList {
  1164. if v == oldEdbInfo.EdbInfoId {
  1165. extraConf.EdbInfoIdList[k] = newEdbInfo.EdbInfoId
  1166. }
  1167. }
  1168. // 更新图表配置信息
  1169. // 重新序列化
  1170. configJson, e := json.Marshal(extraConf)
  1171. if e != nil {
  1172. err = e
  1173. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1174. return
  1175. }
  1176. configStr := string(configJson)
  1177. chartInfo.ExtraConfig = configStr
  1178. updateStr = append(updateStr, "ExtraConfig")
  1179. } else if chartInfo.Source == utils.CHART_SOURCE_LINE_EQUATION {
  1180. //解析配置内容
  1181. var lineChartInfoConfig request.LineChartInfoReq
  1182. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  1183. if err != nil {
  1184. errmsg = "获取图表配置信息失败 json.Unmarshal:Err:" + err.Error()
  1185. return
  1186. }
  1187. xEdbInfoIdList := lineChartInfoConfig.XEdbInfoIdList
  1188. yEdbInfoIdList := lineChartInfoConfig.YEdbInfoIdList
  1189. if len(xEdbInfoIdList) > 0 {
  1190. // 循环判断是否存在
  1191. for k, xEdbInfoId := range xEdbInfoIdList {
  1192. if xEdbInfoId == oldEdbInfo.EdbInfoId {
  1193. xEdbInfoIdList[k] = newEdbInfo.EdbInfoId
  1194. }
  1195. }
  1196. }
  1197. if len(yEdbInfoIdList) > 0 {
  1198. // 循环判断是否存在
  1199. for k, yEdbInfoId := range yEdbInfoIdList {
  1200. if yEdbInfoId == oldEdbInfo.EdbInfoId {
  1201. yEdbInfoIdList[k] = newEdbInfo.EdbInfoId
  1202. }
  1203. }
  1204. }
  1205. // 替换新的指标信息
  1206. lineChartInfoConfig.XEdbInfoIdList = xEdbInfoIdList
  1207. lineChartInfoConfig.YEdbInfoIdList = yEdbInfoIdList
  1208. // 重新序列化
  1209. lineChartInfoConfigJson, e := json.Marshal(lineChartInfoConfig)
  1210. if e != nil {
  1211. err = e
  1212. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1213. return
  1214. }
  1215. lineChartInfoConfigStr := string(lineChartInfoConfigJson)
  1216. // 更新图表配置信息
  1217. chartInfo.ExtraConfig = lineChartInfoConfigStr
  1218. updateStr = append(updateStr, "ExtraConfig")
  1219. } else if chartInfo.ChartType == utils.CHART_TYPE_SECTION_SCATTER {
  1220. //解析配置内容
  1221. var tmpExtraConfig SectionScatterReq
  1222. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &tmpExtraConfig)
  1223. if err != nil {
  1224. errmsg = "获取截面散点图配置信息失败 json.Unmarshal:Err:" + err.Error()
  1225. return
  1226. }
  1227. //找到指标信息,并替换
  1228. if len(tmpExtraConfig.SeriesList) > 0 {
  1229. for k1, series := range tmpExtraConfig.SeriesList {
  1230. for k2, item := range series.EdbInfoList {
  1231. if item.XEdbInfoId == oldEdbInfo.EdbInfoId {
  1232. tmpExtraConfig.SeriesList[k1].EdbInfoList[k2].XEdbInfoId = newEdbInfo.EdbInfoId
  1233. }
  1234. if item.YEdbInfoId == oldEdbInfo.EdbInfoId {
  1235. tmpExtraConfig.SeriesList[k1].EdbInfoList[k2].YEdbInfoId = newEdbInfo.EdbInfoId
  1236. }
  1237. }
  1238. }
  1239. }
  1240. // 重新序列化
  1241. sectionScatterConfigJson, e := json.Marshal(tmpExtraConfig)
  1242. if e != nil {
  1243. err = e
  1244. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1245. return
  1246. }
  1247. sectionScatterConfigStr := string(sectionScatterConfigJson)
  1248. // 更新图表配置信息
  1249. chartInfo.ExtraConfig = sectionScatterConfigStr
  1250. updateStr = append(updateStr, "ExtraConfig")
  1251. } else if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  1252. //解析配置内容
  1253. var tmpExtraConfig ChartSectionExtraConf
  1254. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &tmpExtraConfig)
  1255. if err != nil {
  1256. errmsg = "获取截面散点图配置信息失败 json.Unmarshal:Err:" + err.Error()
  1257. return
  1258. }
  1259. //找到指标信息,并替换
  1260. if len(tmpExtraConfig.DateConfList) > 0 {
  1261. for k1, item := range tmpExtraConfig.DateConfList {
  1262. if item.EdbInfoId > 0 && item.EdbInfoId == oldEdbInfo.EdbInfoId {
  1263. tmpExtraConfig.DateConfList[k1].EdbInfoId = newEdbInfo.EdbInfoId
  1264. }
  1265. }
  1266. }
  1267. // 重新序列化
  1268. configJson, e := json.Marshal(tmpExtraConfig)
  1269. if e != nil {
  1270. err = e
  1271. errmsg = "图表配置信息序列化失败:json.Marshal Err: " + e.Error()
  1272. return
  1273. }
  1274. configStr := string(configJson)
  1275. // 更新图表配置信息
  1276. chartInfo.ExtraConfig = configStr
  1277. updateStr = append(updateStr, "ExtraConfig")
  1278. }
  1279. }
  1280. if len(updateStr) > 0 {
  1281. updateStr = append(updateStr, "ModifyTime")
  1282. chartInfo.ModifyTime = time.Now()
  1283. err = chartInfo.Update(updateStr)
  1284. if err != nil {
  1285. errmsg = "更新图表信息失败:chartInfo.Update Err: " + err.Error()
  1286. return
  1287. }
  1288. }
  1289. }
  1290. }
  1291. // 查询所有的图表信息
  1292. if len(chartEdbMappingList) > 0 {
  1293. chartInfoIdList := make([]string, 0)
  1294. for _, mv := range chartEdbMappingList {
  1295. //获取图表所有指标信息
  1296. chartEdbList := make([]*ChartEdbInfoMapping, 0)
  1297. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=?`
  1298. _, err = to.Raw(csql, mv.ChartInfoId).QueryRows(&chartEdbList)
  1299. if err != nil {
  1300. errmsg = "获取图表所有指标信息失败:Err:" + err.Error()
  1301. return
  1302. }
  1303. // 查询图表信息
  1304. var minData, maxData float64
  1305. minData = newEdbInfo.MinValue
  1306. maxData = newEdbInfo.MaxValue
  1307. for _, cv := range chartEdbList {
  1308. if mv.IsAxis == cv.IsAxis {
  1309. if minData > cv.MinData {
  1310. minData = cv.MinData
  1311. }
  1312. if maxData < cv.MaxData {
  1313. maxData = cv.MaxData
  1314. }
  1315. }
  1316. }
  1317. //修改图表关联指标
  1318. rsql := ` UPDATE chart_edb_mapping SET edb_info_id=?,max_data=?,min_data=?,modify_time=NOW() WHERE chart_edb_mapping_id=? `
  1319. _, err = to.Raw(rsql, newEdbInfo.EdbInfoId, maxData, minData, mv.ChartEdbMappingId).Exec()
  1320. if err != nil {
  1321. errmsg = "更新图库指标信息失败:Err:" + err.Error()
  1322. return
  1323. }
  1324. rsql = ` UPDATE chart_series_edb_mapping SET edb_info_id=? WHERE edb_info_id=? and chart_info_id=?`
  1325. _, err = to.Raw(rsql, newEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoType, mv.ChartInfoId).Exec()
  1326. if err != nil {
  1327. errmsg = "更新图库系列指标信息失败:Err:" + err.Error()
  1328. return
  1329. }
  1330. chartInfoIdList = append(chartInfoIdList, fmt.Sprint(mv.ChartInfoId))
  1331. }
  1332. logMsg += `涉及到的图表id:` + strings.Join(chartInfoIdList, ",") + ";"
  1333. }
  1334. }
  1335. //替换计算指标
  1336. {
  1337. //获取所有包含的计算指标
  1338. mappingList := make([]*EdbInfoCalculateMapping, 0)
  1339. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
  1340. _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&mappingList)
  1341. if err != nil {
  1342. errmsg = "获取计算指标关联基础指标信息失败:Err:" + err.Error()
  1343. return
  1344. }
  1345. replaceCalculateTotal = len(mappingList)
  1346. //计算指标
  1347. if len(mappingList) > 0 {
  1348. edbInfoIdList := make([]string, 0)
  1349. for _, mv := range mappingList {
  1350. //如果即将替换的指标与当前指标id一致,那么就退出当前循环,进入下一循环
  1351. if mv.EdbInfoId == newEdbInfo.EdbInfoId {
  1352. continue
  1353. }
  1354. //替换原指标
  1355. 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=? `
  1356. _, err = to.Raw(msql, newEdbInfo.EdbInfoId, newEdbInfo.EdbCode, newEdbInfo.EdbName, newEdbInfo.Source, newEdbInfo.SourceName, mv.EdbInfoCalculateMappingId).Exec()
  1357. if err != nil {
  1358. return
  1359. }
  1360. relationEdbInfoIdList = append(relationEdbInfoIdList, mv.EdbInfoId)
  1361. edbInfoIdList = append(edbInfoIdList, fmt.Sprint(mv.EdbInfoId))
  1362. }
  1363. logMsg += `涉及到的指标id:` + strings.Join(edbInfoIdList, ",") + ";"
  1364. }
  1365. }
  1366. // 替换预测指标中的来源指标
  1367. {
  1368. //获取所有包含的计算指标
  1369. predictEdbConfList := make([]*PredictEdbConf, 0)
  1370. msql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? GROUP BY predict_edb_info_id `
  1371. _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&predictEdbConfList)
  1372. if err != nil {
  1373. errmsg = "获取关联的预测指标信息失败:Err:" + err.Error()
  1374. return
  1375. }
  1376. replaceCalculateTotal += len(predictEdbConfList)
  1377. //替换预测指标的来源指标
  1378. msql = `UPDATE predict_edb_conf SET source_edb_info_id=? WHERE source_edb_info_id=? `
  1379. _, err = to.Raw(msql, newEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoId).Exec()
  1380. if err != nil {
  1381. return
  1382. }
  1383. if len(predictEdbConfList) > 0 {
  1384. edbInfoIdList := make([]string, 0)
  1385. for _, v := range predictEdbConfList {
  1386. relationEdbInfoIdList = append(relationEdbInfoIdList, v.PredictEdbInfoId)
  1387. edbInfoIdList = append(edbInfoIdList, fmt.Sprint(v.PredictEdbInfoId))
  1388. }
  1389. logMsg += `涉及到的预测指标id:` + strings.Join(edbInfoIdList, ",") + ";"
  1390. }
  1391. }
  1392. return
  1393. }
  1394. type EdbInfoView struct {
  1395. EdbInfoId int `orm:"column(edb_info_id);pk"`
  1396. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  1397. SourceName string `description:"来源名称"`
  1398. Source int `description:"来源id"`
  1399. EdbCode string `description:"指标编码"`
  1400. EdbName string `description:"指标名称"`
  1401. EdbNameSource string `description:"指标名称来源"`
  1402. Frequency string `description:"频率"`
  1403. Unit string `description:"单位"`
  1404. StartDate string `description:"起始日期"`
  1405. EndDate string `description:"终止日期"`
  1406. ClassifyId int `description:"分类id"`
  1407. SysUserId int
  1408. SysUserRealName string
  1409. UniqueCode string `description:"指标唯一编码"`
  1410. CreateTime string
  1411. ModifyTime string
  1412. MinValue float64 `description:"指标最小值"`
  1413. MaxValue float64 `description:"指标最大值"`
  1414. CalculateFormula string `description:"计算公式"`
  1415. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  1416. Sort int `description:"排序字段"`
  1417. IsUpdate int `description:"当天是否已更新,1:未更新,2:已更新"`
  1418. LatestDate string `description:"数据最新日期(实际日期)"`
  1419. LatestValue float64 `description:"数据最新值(实际值)"`
  1420. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  1421. SubSourceName string `description:"子数据来源名称"`
  1422. IndicatorCode string `description:"指标代码"`
  1423. StockCode string `description:"证券代码"`
  1424. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  1425. }
  1426. // 获取指标的所有计算指标,以及计算指标所依赖计算指标
  1427. func GetAllCalculateByEdbInfoId(edbInfoId int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1428. o := orm.NewOrmUsingDB("data")
  1429. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
  1430. _, err = o.Raw(msql, edbInfoId).QueryRows(&mappingList)
  1431. if err != nil {
  1432. return
  1433. }
  1434. return
  1435. }
  1436. // 获取指标的所有计算指标,以及计算指标所依赖计算指标
  1437. func GetAllCalculateByEdbInfoIds(edbInfoIds []int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1438. o := orm.NewOrmUsingDB("data")
  1439. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) GROUP BY edb_info_id `
  1440. _, err = o.Raw(msql, edbInfoIds).QueryRows(&mappingList)
  1441. if err != nil {
  1442. return
  1443. }
  1444. return
  1445. }
  1446. func GetAllCalculate(edbInfoId int, edbInfoMap map[int]int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1447. calculateList, err := GetAllCalculateByEdbInfoId(edbInfoId)
  1448. if err != nil && err.Error() != utils.ErrNoRow() {
  1449. return
  1450. }
  1451. for _, item := range calculateList {
  1452. _, ok := edbInfoMap[item.EdbInfoId]
  1453. if !ok {
  1454. edbInfoMap[item.EdbInfoId] = item.EdbInfoId
  1455. mappingList = append(mappingList, item)
  1456. newCalculateInfoArr, _ := GetAllCalculate(item.EdbInfoId, edbInfoMap)
  1457. mappingList = append(mappingList, newCalculateInfoArr...)
  1458. }
  1459. }
  1460. return
  1461. }
  1462. // GetAllCalculateByEdbInfoIdV2 获取计算指标的所有所依赖的指标(基础指标+计算指标)
  1463. func GetAllCalculateByEdbInfoIdV2(edbInfoId int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1464. o := orm.NewOrmUsingDB("data")
  1465. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE edb_info_id=? GROUP BY from_edb_info_id `
  1466. _, err = o.Raw(msql, edbInfoId).QueryRows(&mappingList)
  1467. if err != nil {
  1468. return
  1469. }
  1470. return
  1471. }
  1472. // GetAllCalculateV2 获取所有的指标(如果下层指标包含了待替换指标,那么就不加入)
  1473. func GetAllCalculateV2(oldEdbInfoId, replaceEdbInfoId int, edbInfoMap map[int]int) (mappingList []*EdbInfoCalculateMapping, err error) {
  1474. calculateList, err := GetAllCalculateByEdbInfoId(oldEdbInfoId)
  1475. if err != nil && err.Error() != utils.ErrNoRow() {
  1476. return
  1477. }
  1478. tmpMappingList := make([]*EdbInfoCalculateMapping, 0)
  1479. for _, item := range calculateList {
  1480. //如果计算指标里面存在即将替换的指标id,那么退出当前循环,进入下一循环
  1481. if item.EdbInfoId == replaceEdbInfoId {
  1482. err = fmt.Errorf("指标重复1")
  1483. return
  1484. }
  1485. //获取该指标的依赖指标列表,如果依赖指标列表中存在即将替换的指标,那么过滤该指标
  1486. childCalculateList, tmpErr := GetAllCalculateByEdbInfoIdV2(item.EdbInfoId)
  1487. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1488. err = tmpErr
  1489. return
  1490. }
  1491. for _, childCalculate := range childCalculateList {
  1492. if childCalculate.FromEdbInfoId == replaceEdbInfoId {
  1493. err = fmt.Errorf("指标重复2")
  1494. return
  1495. }
  1496. }
  1497. _, ok := edbInfoMap[item.EdbInfoId]
  1498. if !ok {
  1499. edbInfoMap[item.EdbInfoId] = item.EdbInfoId
  1500. newCalculateInfoArr, tmpErr := GetAllCalculateV2(item.EdbInfoId, replaceEdbInfoId, edbInfoMap)
  1501. if tmpErr != nil {
  1502. err = tmpErr
  1503. continue
  1504. } else {
  1505. mappingList = append(mappingList, item)
  1506. tmpMappingList = append(tmpMappingList, newCalculateInfoArr...)
  1507. }
  1508. }
  1509. }
  1510. mappingList = append(mappingList, tmpMappingList...)
  1511. return
  1512. }
  1513. // EdbInfoFilterDataResp 搜索指标列表数据返回
  1514. type EdbInfoFilterDataResp struct {
  1515. Paging *paging.PagingItem
  1516. List []*EdbInfoList
  1517. }
  1518. // GetEdbInfoFilterList 获取指指标列表数据接口
  1519. func GetEdbInfoFilterList(condition string, pars []interface{}, startSize, pageSize int) (total int64, items []*EdbInfoList, err error) {
  1520. o := orm.NewOrmUsingDB("data")
  1521. sql := ` SELECT count(1) total FROM edb_info where 1=1 ` + condition + ` ORDER BY edb_info_id DESC `
  1522. err = o.Raw(sql, pars).QueryRow(&total)
  1523. if err != nil {
  1524. return
  1525. }
  1526. var ormList []*EdbInfoOrm
  1527. items = make([]*EdbInfoList, 0)
  1528. sql = ` SELECT * FROM edb_info where 1=1 ` + condition + ` ORDER BY edb_info_id DESC LIMIT ?,? `
  1529. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&ormList)
  1530. if err != nil {
  1531. return
  1532. }
  1533. for _, ormItem := range ormList {
  1534. items = append(items, ormItem.ToList())
  1535. }
  1536. return
  1537. }
  1538. // SetEdbInfoImageReq 设置指标图片
  1539. type SetEdbInfoImageReq struct {
  1540. EdbInfoId int `description:"指标ID"`
  1541. ImageUrl string `description:"指标图片地址"`
  1542. }
  1543. // GetNextEdbInfoByCondition 根据条件获取下一个指标
  1544. func GetNextEdbInfoByCondition(condition string, pars []interface{}) (item *EdbInfo, err error) {
  1545. var edbInfoOrm *EdbInfoOrm
  1546. o := orm.NewOrmUsingDB("data")
  1547. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1548. if condition != "" {
  1549. sql += condition
  1550. }
  1551. sql += " ORDER BY sort asc , edb_info_id asc LIMIT 1 "
  1552. err = o.Raw(sql, pars).QueryRow(&edbInfoOrm)
  1553. if err != nil {
  1554. return
  1555. }
  1556. item = edbInfoOrm.ToInfo()
  1557. return
  1558. }
  1559. // GetNextEdbInfo 根据分类id获取下一个 指标
  1560. func GetNextEdbInfo(classifyId, classifySort, classifyType, edbInfoType int) (item *EdbInfo, err error) {
  1561. var edbInfoOrm *EdbInfoOrm
  1562. o := orm.NewOrmUsingDB("data")
  1563. sql := ` SELECT b.* FROM edb_classify AS a
  1564. INNER JOIN edb_info AS b ON a.classify_id=b.classify_id
  1565. WHERE (a.sort>? OR (a.sort=? and a.classify_id>?) )
  1566. AND a.classify_type=? AND b.edb_info_type=?
  1567. ORDER BY a.sort ASC,b.sort asc,b.edb_info_id asc
  1568. LIMIT 1 `
  1569. err = o.Raw(sql, classifySort, classifySort, classifyId, classifyType, edbInfoType).QueryRow(&edbInfoOrm)
  1570. if err != nil {
  1571. return
  1572. }
  1573. item = edbInfoOrm.ToInfo()
  1574. return
  1575. }
  1576. // GetEdbInfoByEdbCodeList 根据指标code集合获取指标列表
  1577. func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo, err error) {
  1578. num := len(edbCodeList)
  1579. if num <= 0 {
  1580. return
  1581. }
  1582. var ormList []*EdbInfoOrm
  1583. items = make([]*EdbInfo, 0)
  1584. o := orm.NewOrmUsingDB("data")
  1585. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) `
  1586. _, err = o.Raw(sql, source, edbCodeList).QueryRows(&ormList)
  1587. if err != nil {
  1588. return
  1589. }
  1590. for _, ormItem := range ormList {
  1591. items = append(items, ormItem.ToInfo())
  1592. }
  1593. return
  1594. }
  1595. // GetEdbInfoByConditionCount 根据条件获取指标列表数据总数
  1596. func GetEdbInfoByConditionCount(condition string, pars []interface{}) (count int, err error) {
  1597. o := orm.NewOrmUsingDB("data")
  1598. sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
  1599. if condition != "" {
  1600. sql += condition
  1601. }
  1602. err = o.Raw(sql, pars).QueryRow(&count)
  1603. return
  1604. }
  1605. // GetEdbInfoListByCondition 根据条件获取指标列表数据
  1606. func GetEdbInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int, orderDesc string) (items []*EdbInfoList, err error) {
  1607. var ormList []*EdbInfoOrm
  1608. items = make([]*EdbInfoList, 0)
  1609. o := orm.NewOrmUsingDB("data")
  1610. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1611. if condition != "" {
  1612. sql += condition
  1613. }
  1614. if orderDesc == `` {
  1615. orderDesc = ` ASC `
  1616. }
  1617. sql += ` ORDER BY edb_info_id `
  1618. sql += orderDesc
  1619. if pageSize > 0 {
  1620. sql += ` LIMIT ?,? `
  1621. pars = append(pars, startSize, pageSize)
  1622. }
  1623. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  1624. if err != nil {
  1625. return
  1626. }
  1627. for _, ormItem := range ormList {
  1628. items = append(items, ormItem.ToList())
  1629. }
  1630. return
  1631. }
  1632. // GetEdbInfoListV2ByCondition 根据条件获取指标列表数据(EdbInfo原始数据结构)
  1633. func GetEdbInfoListV2ByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfo, err error) {
  1634. var ormList []*EdbInfoOrm
  1635. items = make([]*EdbInfo, 0)
  1636. o := orm.NewOrmUsingDB("data")
  1637. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1638. if condition != "" {
  1639. sql += condition
  1640. }
  1641. sql += ` ORDER BY edb_info_id ASC LIMIT ?,? `
  1642. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&ormList)
  1643. if err != nil {
  1644. return
  1645. }
  1646. for _, ormItem := range ormList {
  1647. items = append(items, ormItem.ToInfo())
  1648. }
  1649. return
  1650. }
  1651. // GetEdbInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1652. func GetEdbInfoListGroupByUserId(edbIdList []string) (items []*EdbInfo, err error) {
  1653. num := len(edbIdList)
  1654. if num <= 0 {
  1655. return
  1656. }
  1657. var ormList []*EdbInfoOrm
  1658. items = make([]*EdbInfo, 0)
  1659. o := orm.NewOrmUsingDB("data")
  1660. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  1661. _, err = o.Raw(sql, edbIdList).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. // GetEdbInfoListByEdbInfoId
  1671. // @Description: 根据指标id列表获取列表信息
  1672. // @param edbIdList
  1673. // @return items
  1674. // @return err
  1675. func GetEdbInfoListByEdbInfoId(edbIdList []string) (items []*EdbInfo, err error) {
  1676. num := len(edbIdList)
  1677. if num <= 0 {
  1678. return
  1679. }
  1680. var ormList []*EdbInfoOrm
  1681. items = make([]*EdbInfo, 0)
  1682. o := orm.NewOrmUsingDB("data")
  1683. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1684. _, err = o.Raw(sql, edbIdList).QueryRows(&ormList)
  1685. if err != nil {
  1686. return
  1687. }
  1688. for _, ormItem := range ormList {
  1689. items = append(items, ormItem.ToInfo())
  1690. }
  1691. return
  1692. }
  1693. // GetEdbInfoListByUserId
  1694. // @Description: 根据指标id列表获取列表信息
  1695. // @param userIdList []int
  1696. // @param edbInfoType int
  1697. // @return items
  1698. // @return err
  1699. func GetEdbInfoListByUserId(userIdList []int, edbInfoType int) (items []*EdbInfo, err error) {
  1700. num := len(userIdList)
  1701. if num <= 0 {
  1702. return
  1703. }
  1704. var ormList []*EdbInfoOrm
  1705. items = make([]*EdbInfo, 0)
  1706. o := orm.NewOrmUsingDB("data")
  1707. sql := ` SELECT * FROM edb_info WHERE edb_info_type = ? AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1708. _, err = o.Raw(sql, edbInfoType, userIdList).QueryRows(&ormList)
  1709. if err != nil {
  1710. return
  1711. }
  1712. for _, ormItem := range ormList {
  1713. items = append(items, ormItem.ToInfo())
  1714. }
  1715. return
  1716. }
  1717. // ModifyEdbInfoUserIdByCodeList 根据指标code列表修改创建人
  1718. func ModifyEdbInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1719. num := len(edbIdList)
  1720. if num <= 0 {
  1721. return
  1722. }
  1723. o := orm.NewOrmUsingDB("data")
  1724. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1725. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  1726. return
  1727. }
  1728. // ModifyEdbInfoUserIdByOldUserId
  1729. // @Description: 根据旧用户id修改新用户id
  1730. // @author: Roc
  1731. // @datetime 2024-03-25 19:17:09
  1732. // @param edbIdList []string
  1733. // @param userId int
  1734. // @param userName string
  1735. // @return err error
  1736. func ModifyEdbInfoUserIdByOldUserId(oldUserIdList []int, edbInfoType, userId int, userName string) (err error) {
  1737. num := len(oldUserIdList)
  1738. if num <= 0 {
  1739. return
  1740. }
  1741. o := orm.NewOrmUsingDB("data")
  1742. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  1743. _, err = o.Raw(sql, userId, userName, oldUserIdList, edbInfoType).Exec()
  1744. return
  1745. }
  1746. // MoveEdbChartList 图表/指标信息
  1747. type MoveEdbChartList struct {
  1748. DataId string `description:"指标/图表唯一id"`
  1749. Code string `description:"指标code"`
  1750. Name string `description:"指标/图表名称"`
  1751. NameEn string `description:"指标/图表名称"`
  1752. ClassifyName string `description:"分类名称"`
  1753. ClassifyNameEn string `description:"分类名称"`
  1754. CreateUserId int `description:"创建人id"`
  1755. CreateUserName string `description:"创建人名称"`
  1756. }
  1757. // MoveEdbChartListResp 更改创建人返回数据
  1758. type MoveEdbChartListResp struct {
  1759. Paging *paging.PagingItem
  1760. List []MoveEdbChartList
  1761. }
  1762. type EdbChartClassifyResp struct {
  1763. List []*EdbChartClassify
  1764. }
  1765. type EdbChartClassify struct {
  1766. ClassifyId int
  1767. ClassifyName string
  1768. ParentId int
  1769. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1770. Child []*EdbChartClassify
  1771. }
  1772. // EdbInfoDataSeasonalResp 指标季节性数据返回
  1773. type EdbInfoDataSeasonalResp struct {
  1774. EdbInfo *EdbInfo
  1775. DataList interface{}
  1776. }
  1777. // SetEdbDataInsertConfigReq 设置插入规则的请求
  1778. type SetEdbDataInsertConfigReq struct {
  1779. EdbInfoId int `description:"指标ID"`
  1780. Date string `description:"日期"`
  1781. Value string `description:"值"`
  1782. }
  1783. // GetEdbInfoByClassifyId 用于分类展示
  1784. func GetEdbInfoByClassifyId(classifyId, edbInfoType, adminId int) (items []*EdbClassifyItems, err error) {
  1785. o := orm.NewOrmUsingDB("data")
  1786. 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 = ?`
  1787. pars := []interface{}{classifyId, edbInfoType}
  1788. // 如果筛选了用户id
  1789. if adminId > 0 {
  1790. sql += ` AND sys_user_id = ? `
  1791. pars = append(pars, adminId)
  1792. }
  1793. sql += ` order by sort asc,edb_info_id asc `
  1794. _, err = o.Raw(sql, pars).QueryRows(&items)
  1795. return
  1796. }
  1797. type EdbAndClassify struct {
  1798. EdbInfoId int `description:"指标id"`
  1799. EdbCode string `description:"指标code"`
  1800. UniqueCode string `description:"唯一code"`
  1801. EdbName string `description:"指标名称"`
  1802. ClassifyId int `description:"所属分类id"`
  1803. FirstClassifyId int `description:"第1级的分类id"`
  1804. FirstClassifyName string `description:"第1级的分类名称"`
  1805. SecondClassifyId int `description:"第2级的分类id"`
  1806. SecondClassifyName string `description:"第2级的分类名称"`
  1807. }
  1808. // GetEdbInfoAndClassifyListByEdbIdList 根据指标id列表获取 指标及分类信息
  1809. func GetEdbInfoAndClassifyListByEdbIdList(edbIdList []int) (items []*EdbAndClassify, err error) {
  1810. num := len(edbIdList)
  1811. if num <= 0 {
  1812. return
  1813. }
  1814. o := orm.NewOrmUsingDB("data")
  1815. sql := ` SELECT a.edb_info_id,a.edb_code,a.unique_code,a.edb_name,a.classify_id FROM edb_info AS a
  1816. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1817. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  1818. return
  1819. }
  1820. // TraceEdbInfoResp 指标追溯数据返回
  1821. type TraceEdbInfoResp struct {
  1822. EdbInfoId int `description:"指标id"`
  1823. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  1824. EdbName string `description:"指标名称"`
  1825. EdbNameEn string `description:"指标英文名称"`
  1826. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  1827. RuleTitle string `description:"指标规则"`
  1828. RuleTitleEn string `description:"指标规则(英文)"`
  1829. UniqueCode string `description:"唯一编码"`
  1830. ClassifyId int `description:"分类ID"`
  1831. Child []TraceEdbInfoResp `description:"下级来源"`
  1832. IsStop int8 `description:"是否终止"`
  1833. EdbInfo *EdbInfo `description:"指标信息" json:"-"`
  1834. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  1835. }
  1836. // BeforeAndAfterDateDataResp 前后几期数据
  1837. type BeforeAndAfterDateDataResp struct {
  1838. List []*EdbDataList `description:"list"`
  1839. Date string `description:"实际日期"`
  1840. ShowValue string `description:"展示值"`
  1841. }
  1842. // GetEdbInfoAdminList
  1843. func GetEdbInfoAdminList(edbType int) (list []int, err error) {
  1844. o := orm.NewOrmUsingDB("data")
  1845. sql := ` SELECT sys_user_id FROM edb_info WHERE edb_info_type = ? GROUP BY sys_user_id `
  1846. _, err = o.Raw(sql, edbType).QueryRows(&list)
  1847. return
  1848. }
  1849. type EdbInfoExistCheckResp struct {
  1850. IndexExist bool `description:"指标是否存在:true,存在,false:不存在"`
  1851. ExistStockCodeArr []string `description:"存在的证券代码"`
  1852. ExistEdbCodeArr []string `description:"存在的指标代码"`
  1853. ExistClassifyId []int `description:"存在的分类id"`
  1854. ExistIndexId []int `description:"存在的指标id"`
  1855. ExistEdbInfo []*EdbInfo `description:"存在的指标"`
  1856. }
  1857. type BatchAddEdbInfoReq struct {
  1858. BatchList []*BatchAddEdbInfo
  1859. }
  1860. type BatchAddEdbInfo struct {
  1861. Source int `description:"来源id"`
  1862. EdbName string `description:"指标名称"`
  1863. Frequency string `description:"频率"`
  1864. Unit string `description:"单位"`
  1865. ClassifyId int `description:"分类id"`
  1866. StockCode string `description:"证券代码"`
  1867. EdbCode string `description:"指标编码"`
  1868. ApiExtraPars string `description:"API额外参数"`
  1869. }
  1870. func GetEdbInfoWsdMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  1871. o := orm.NewOrmUsingDB("data")
  1872. sql := ``
  1873. tableName := GetEdbDataTableNameAndSubSource(source, subSource)
  1874. 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=? `
  1875. sql = fmt.Sprintf(sql, tableName)
  1876. err = o.Raw(sql, edbCode).QueryRow(&item)
  1877. if err != nil {
  1878. return
  1879. }
  1880. var latest_value float64
  1881. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  1882. sql = fmt.Sprintf(sql, tableName)
  1883. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  1884. item.LatestValue = latest_value
  1885. return
  1886. }
  1887. // GetEdbInfoByNames 根据名称获取普通的指标
  1888. func GetEdbInfoByNames(edbNames string) (items []*EdbInfoList, err error) {
  1889. var ormList []*EdbInfoOrm
  1890. items = make([]*EdbInfoList, 0)
  1891. o := orm.NewOrmUsingDB("data")
  1892. sql := ` SELECT * FROM edb_info WHERE edb_name IN (` + edbNames + `) AND edb_info_type = 0 `
  1893. _, err = o.Raw(sql).QueryRows(&ormList)
  1894. if err != nil {
  1895. return
  1896. }
  1897. for _, ormItem := range ormList {
  1898. items = append(items, ormItem.ToList())
  1899. }
  1900. return
  1901. }
  1902. func GetSmmEdbInfoMaxAndMinInfo(edbCodes []string) (item *EdbInfoMaxAndMinInfo, err error) {
  1903. o := orm.NewOrmUsingDB("data")
  1904. sql := ``
  1905. 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)) + `)`
  1906. err = o.Raw(sql, edbCodes).QueryRow(&item)
  1907. if err != nil {
  1908. return
  1909. }
  1910. var latest_value float64
  1911. 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 `
  1912. err = o.Raw(sql, edbCodes).QueryRow(&latest_value)
  1913. item.LatestValue = latest_value
  1914. return
  1915. }
  1916. type EdbInfoSmmExistCheckResp struct {
  1917. EdbInfoExistCheckResp
  1918. ExistAll bool `description:"是否全部重复"`
  1919. }
  1920. // GetEdbBaseInfoList
  1921. // @Description: 获取指标库数据列表
  1922. // @author: Roc
  1923. // @datetime 2024-01-10 14:28:22
  1924. // @param condition string
  1925. // @param pars []interface{}
  1926. // @param orderBy string
  1927. // @param startSize int
  1928. // @param pageSize int
  1929. // @return total int
  1930. // @return items []*BaseRefreshEdbInfo
  1931. // @return err error
  1932. func GetEdbBaseInfoList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRefreshEdbInfo, err error) {
  1933. o := orm.NewOrmUsingDB("data")
  1934. // 数量汇总
  1935. totalSql := ` SELECT count(1) FROM edb_info WHERE 1=1 `
  1936. if condition != "" {
  1937. totalSql += condition
  1938. }
  1939. err = o.Raw(totalSql, pars).QueryRow(&total)
  1940. if err != nil {
  1941. return
  1942. }
  1943. // 列表数据
  1944. 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 `
  1945. if condition != "" {
  1946. sql += condition
  1947. }
  1948. if orderBy != "" {
  1949. sql += ` ORDER BY ` + orderBy
  1950. } else {
  1951. sql += ` ORDER BY edb_info_id ASC `
  1952. }
  1953. sql += ` LIMIT ?,? `
  1954. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1955. return
  1956. }
  1957. // ModifyEdbInfoUpdateStatus
  1958. // @Description: 修改指标库停更状态
  1959. // @author: Roc
  1960. // @datetime 2024-01-08 16:23:31
  1961. // @param edbIdList []int
  1962. // @param indexCodeList []string
  1963. // @param isStop int
  1964. // @return err error
  1965. func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int, calculateEdbInfoIds []int) (err error) {
  1966. idNum := len(edbIdList)
  1967. if idNum <= 0 {
  1968. return
  1969. }
  1970. o, err := orm.NewOrmUsingDB("data").Begin()
  1971. if err != nil {
  1972. return
  1973. }
  1974. defer func() {
  1975. if err != nil {
  1976. _ = o.Rollback()
  1977. return
  1978. }
  1979. _ = o.Commit()
  1980. }()
  1981. // 更改指标的更新状态
  1982. sql := ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  1983. _, err = o.Raw(sql, isStop, time.Now(), edbIdList).Exec()
  1984. if err != nil {
  1985. return
  1986. }
  1987. if len(calculateEdbInfoIds) > 0 {
  1988. // 批量更新相关联的指标ID
  1989. sql = ` UPDATE edb_info SET no_update = ?, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  1990. _, err = o.Raw(sql, isStop, time.Now(), calculateEdbInfoIds).Exec()
  1991. if err != nil {
  1992. return
  1993. }
  1994. }
  1995. return
  1996. }
  1997. func GetEdbInfoCount(source int, edbCode string) (count int, err error) {
  1998. o := orm.NewOrmUsingDB("data")
  1999. sql := ` SELECT COUNT(1) AS count FROM edb_info
  2000. WHERE source=? AND edb_code = ?`
  2001. err = o.Raw(sql, source, edbCode).QueryRow(&count)
  2002. return
  2003. }
  2004. // GetEdbInfoByNameArr 根据名称获取指标
  2005. func GetEdbInfoByNameArr(names []string, edbInfoType int) (items []*EdbInfo, err error) {
  2006. if len(names) == 0 {
  2007. return
  2008. }
  2009. var ormList []*EdbInfoOrm
  2010. items = make([]*EdbInfo, 0)
  2011. o := orm.NewOrmUsingDB("data")
  2012. 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)))
  2013. _, err = o.Raw(sql, names, edbInfoType).QueryRows(&ormList)
  2014. if err != nil {
  2015. return
  2016. }
  2017. for _, ormItem := range ormList {
  2018. items = append(items, ormItem.ToInfo())
  2019. }
  2020. return
  2021. }
  2022. // GetEdbInfoByNameArr 根据指标编码获取指标
  2023. func GetEdbInfoByCodeArr(codes []string, edbInfoType int) (items []*EdbInfo, err error) {
  2024. if len(codes) == 0 {
  2025. return
  2026. }
  2027. var ormList []*EdbInfoOrm
  2028. items = make([]*EdbInfo, 0)
  2029. o := orm.NewOrmUsingDB("data")
  2030. 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)))
  2031. _, err = o.Raw(sql, codes, edbInfoType).QueryRows(&ormList)
  2032. if err != nil {
  2033. return
  2034. }
  2035. for _, ormItem := range ormList {
  2036. items = append(items, ormItem.ToInfo())
  2037. }
  2038. return
  2039. }
  2040. // GetEdbCodesBySource 根据来源获取指标编码
  2041. func GetEdbCodesBySource(source int) (items []*EdbInfo, err error) {
  2042. var ormList []*EdbInfoOrm
  2043. items = make([]*EdbInfo, 0)
  2044. o := orm.NewOrmUsingDB("data")
  2045. sql := ` SELECT edb_info_id, edb_code, unique_code, classify_id FROM edb_info WHERE source = ? `
  2046. _, err = o.Raw(sql, source).QueryRows(&ormList)
  2047. if err != nil {
  2048. return
  2049. }
  2050. for _, ormItem := range ormList {
  2051. items = append(items, ormItem.ToInfo())
  2052. }
  2053. return
  2054. }
  2055. // GetAllEdbDataListData
  2056. // @Description: 获取指标的所有数据
  2057. // @author: Roc
  2058. // @datetime 2024-05-07 15:18:27
  2059. // @param edbInfoId int
  2060. // @param source int
  2061. // @param subSource int
  2062. // @param startDataTime string
  2063. // @return dataList []*EdbData
  2064. // @return err error
  2065. func GetAllEdbDataListData(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2066. // 自有数据需要额外处理(从mongo获取)
  2067. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  2068. return getAllDataByMongo(edbInfoId, source, subSource, startDataTime)
  2069. }
  2070. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  2071. return getThsHfAllDataByMongo(edbInfoId, source, subSource, startDataTime)
  2072. }
  2073. // 默认走mysql
  2074. return getAllDataByMysql(edbInfoId, source, subSource, startDataTime)
  2075. }
  2076. // getAllDataByMysql
  2077. // @Description: 从mysql获取指标的所有数据
  2078. // @author: Roc
  2079. // @datetime 2024-05-07 15:18:41
  2080. // @param edbInfoId int
  2081. // @param source int
  2082. // @param subSource int
  2083. // @param startDataTime string
  2084. // @return dataList []*data_manage.EdbData
  2085. // @return err error
  2086. func getAllDataByMysql(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2087. dataList = make([]*EdbData, 0)
  2088. var dataCondition string
  2089. var dataPars []interface{}
  2090. dataCondition += ` AND edb_info_id=? `
  2091. dataPars = append(dataPars, edbInfoId)
  2092. // 结束日期
  2093. if startDataTime != "" {
  2094. dataCondition += ` AND data_time > ? `
  2095. dataPars = append(dataPars, startDataTime)
  2096. }
  2097. // 获取列表数据
  2098. dataList, err = GetAllEdbDataListByCondition(dataCondition, dataPars, source, subSource)
  2099. if err != nil {
  2100. return
  2101. }
  2102. return
  2103. }
  2104. // getAllDataByMongo
  2105. // @Description: 从mongo获取指标的所有数据
  2106. // @author: Roc
  2107. // @datetime 2024-05-07 15:18:53
  2108. // @param edbInfoId int
  2109. // @param source int
  2110. // @param subSource int
  2111. // @param startDataTime string
  2112. // @return dataList []*data_manage.EdbData
  2113. // @return err error
  2114. func getAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2115. dataList = make([]*EdbData, 0)
  2116. mogDataObj := mgo.EdbDataBusiness{}
  2117. // 构建查询条件
  2118. queryConditions := bson.M{
  2119. "edb_info_id": edbInfoId,
  2120. }
  2121. // 开始日期
  2122. dateCondition, err := mgo.BuildDateCondition(startDataTime, "")
  2123. if err != nil {
  2124. return
  2125. }
  2126. if len(dateCondition) > 0 {
  2127. queryConditions["data_time"] = dateCondition
  2128. }
  2129. // 获取列表数据
  2130. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"-data_time"})
  2131. if tmpErr != nil {
  2132. err = tmpErr
  2133. return
  2134. }
  2135. for k, v := range tmpDataList {
  2136. dataList = append(dataList, &EdbData{
  2137. EdbDataId: k + 1,
  2138. EdbInfoId: v.EdbInfoId,
  2139. DataTime: v.DataTime.Format(utils.FormatDate),
  2140. Value: v.Value,
  2141. })
  2142. }
  2143. return
  2144. }
  2145. // GetEdbClassifyIdListBySource 获取普通指标的分类列表
  2146. func GetEdbClassifyIdListBySource(source int) (items []int, err error) {
  2147. o := orm.NewOrmUsingDB("data")
  2148. sql := `SELECT distinct classify_id FROM edb_info WHERE source = ? and edb_info_type=0`
  2149. _, err = o.Raw(sql, source).QueryRows(&items)
  2150. return
  2151. }
  2152. // GetEdbInfoByClassifyIdAndSource 用于分类展示
  2153. func GetEdbInfoByClassifyIdAndSource(classifyId, edbInfoType, source int) (items []*EdbClassifyItems, err error) {
  2154. o := orm.NewOrmUsingDB("data")
  2155. 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 =?`
  2156. pars := []interface{}{classifyId, edbInfoType, source}
  2157. sql += ` order by sort asc,edb_info_id asc `
  2158. _, err = o.Raw(sql, pars).QueryRows(&items)
  2159. return
  2160. }
  2161. type ReplaceEdbInfoItem struct {
  2162. OldEdbInfo *EdbInfo
  2163. NewEdbInfo *EdbInfo
  2164. }
  2165. type EdbInfoEditRecord struct {
  2166. EdbInfoId int `description:"指标ID"`
  2167. EdbName string `description:"指标名称"`
  2168. Frequency string `description:"频率"`
  2169. Unit string `description:"单位"`
  2170. ClassifyId int `description:"分类id"`
  2171. CalculateFormula string `description:"计算公式"`
  2172. OperateUserId int `description:"操作人id"`
  2173. OperateUserRealName string `description:"操作人姓名"`
  2174. }
  2175. func ModifyEdbInfoBaseTimeById(edbInfoId int, cTime time.Time) (err error) {
  2176. o := orm.NewOrmUsingDB("data")
  2177. // 更新修改时间
  2178. sql := ` UPDATE edb_info SET base_modify_time = ? WHERE edb_info_id = ? `
  2179. _, err = o.Raw(sql, cTime, edbInfoId).Exec()
  2180. return
  2181. }
  2182. func GetEdbInfoFieldList(cond string, pars []interface{}, fields []string) (items []*EdbInfo, err error) {
  2183. field := " * "
  2184. if len(fields) > 0 {
  2185. field = strings.Join(fields, ",")
  2186. }
  2187. var ormList []*EdbInfoOrm
  2188. items = make([]*EdbInfo, 0)
  2189. o := orm.NewOrmUsingDB("data")
  2190. sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s `, field, cond)
  2191. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  2192. if err != nil {
  2193. return
  2194. }
  2195. for _, ormItem := range ormList {
  2196. items = append(items, ormItem.ToInfo())
  2197. }
  2198. return
  2199. }
  2200. // EdbInfoExtra 指标额外数据-extra字段
  2201. type EdbInfoExtra struct {
  2202. ApiExtraPars string `description:"API-额外参数(如同花顺日期序列)"`
  2203. }
  2204. func GetEdbInfoListByCond(condition string, pars []interface{}) (items []*EdbInfoList, err error) {
  2205. var ormList []*EdbInfoOrm
  2206. items = make([]*EdbInfoList, 0)
  2207. o := orm.NewOrmUsingDB("data")
  2208. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  2209. if condition != "" {
  2210. sql += condition
  2211. }
  2212. sql += ` ORDER BY create_time DESC `
  2213. _, err = o.Raw(sql, pars).QueryRows(&ormList)
  2214. if err != nil {
  2215. return
  2216. }
  2217. for _, ormItem := range ormList {
  2218. items = append(items, ormItem.ToList())
  2219. }
  2220. return
  2221. }
  2222. func GetThsHfEdbInfoMaxAndMinInfoByMongo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  2223. mogDataObj := new(mgo.EdbDataThsHf)
  2224. pipeline := []bson.M{
  2225. {"$match": bson.M{"edb_code": edbCode}},
  2226. {"$group": bson.M{
  2227. "_id": nil,
  2228. "min_date": bson.M{"$min": "$data_time"},
  2229. "max_date": bson.M{"$max": "$data_time"},
  2230. "min_value": bson.M{"$min": "$value"},
  2231. "max_value": bson.M{"$max": "$value"},
  2232. }},
  2233. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  2234. }
  2235. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  2236. if err != nil {
  2237. fmt.Println("EdbDataThsHf getEdbDataThsHfList Err:" + err.Error())
  2238. return
  2239. }
  2240. if !result.MaxDate.IsZero() {
  2241. whereQuery := bson.M{"edb_code": edbCode, "data_time": result.MaxDate}
  2242. selectParam := bson.D{{"value", 1}, {"_id", 0}}
  2243. latestValue, tmpErr := mogDataObj.GetLatestValue(whereQuery, selectParam)
  2244. if tmpErr != nil {
  2245. err = tmpErr
  2246. return
  2247. }
  2248. result.LatestValue = latestValue.Value
  2249. result.EndValue = latestValue.Value
  2250. }
  2251. item = &EdbInfoMaxAndMinInfo{
  2252. MinDate: result.MinDate.Format(utils.FormatDate),
  2253. MaxDate: result.MaxDate.Format(utils.FormatDate),
  2254. MinValue: result.MinValue,
  2255. MaxValue: result.MaxValue,
  2256. LatestValue: result.LatestValue,
  2257. }
  2258. return
  2259. }
  2260. func getThsHfAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  2261. dataList = make([]*EdbData, 0)
  2262. mogDataObj := mgo.EdbDataThsHf{}
  2263. // 构建查询条件
  2264. queryConditions := bson.M{
  2265. "edb_info_id": edbInfoId,
  2266. }
  2267. // 开始日期
  2268. dateCondition, err := mgo.BuildDateCondition(startDataTime, "")
  2269. if err != nil {
  2270. return
  2271. }
  2272. if len(dateCondition) > 0 {
  2273. queryConditions["data_time"] = dateCondition
  2274. }
  2275. // 获取列表数据
  2276. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"-data_time"})
  2277. if tmpErr != nil {
  2278. err = tmpErr
  2279. return
  2280. }
  2281. for k, v := range tmpDataList {
  2282. dataList = append(dataList, &EdbData{
  2283. EdbDataId: k + 1,
  2284. EdbInfoId: v.EdbInfoId,
  2285. DataTime: v.DataTime.Format(utils.FormatDate),
  2286. Value: v.Value,
  2287. })
  2288. }
  2289. return
  2290. }
  2291. type EdbNameCheckResult struct {
  2292. EdbCode string
  2293. EdbName string
  2294. Exist bool
  2295. }
  2296. // UpdateEdbClassifyIdByChartInfoId
  2297. func UpdateEdbClassifyIdByChartInfoId(chartInfoIds []int, classifyId int) (err error) {
  2298. o := orm.NewOrmUsingDB("data")
  2299. sql := ` update edb_info set classify_id = ? WHERE edb_info_id in (` + utils.GetOrmInReplace(len(chartInfoIds)) + `) `
  2300. _, err = o.Raw(sql, classifyId, chartInfoIds).Exec()
  2301. return
  2302. }