edb_info.go 72 KB

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