edb_info.go 70 KB

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