edb_info.go 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  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. msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
  1079. err = to.Raw(msql, oldEdbInfo.EdbInfoId).Scan(&mappingList).Error
  1080. if err != nil {
  1081. errmsg = "获取计算指标关联基础指标信息失败:Err:" + err.Error()
  1082. return
  1083. }
  1084. replaceCalculateTotal = len(mappingList)
  1085. //计算指标
  1086. if len(mappingList) > 0 {
  1087. edbInfoIdList := make([]string, 0)
  1088. for _, mv := range mappingList {
  1089. //如果即将替换的指标与当前指标id一致,那么就退出当前循环,进入下一循环
  1090. if mv.EdbInfoId == newEdbInfo.EdbInfoId {
  1091. continue
  1092. }
  1093. //替换原指标
  1094. 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=? `
  1095. err = to.Exec(msql, newEdbInfo.EdbInfoId, newEdbInfo.EdbCode, newEdbInfo.EdbName, newEdbInfo.Source, newEdbInfo.SourceName, mv.EdbInfoCalculateMappingId).Error
  1096. if err != nil {
  1097. return
  1098. }
  1099. relationEdbInfoIdList = append(relationEdbInfoIdList, mv.EdbInfoId)
  1100. edbInfoIdList = append(edbInfoIdList, fmt.Sprint(mv.EdbInfoId))
  1101. }
  1102. logMsg += `涉及到的指标id:` + strings.Join(edbInfoIdList, ",") + ";"
  1103. }
  1104. }
  1105. // 替换预测指标中的来源指标
  1106. {
  1107. //获取所有包含的计算指标
  1108. predictEdbConfList := make([]*PredictEdbConf, 0)
  1109. msql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? GROUP BY predict_edb_info_id `
  1110. err = to.Raw(msql, oldEdbInfo.EdbInfoId).Scan(&predictEdbConfList).Error
  1111. if err != nil {
  1112. errmsg = "获取关联的预测指标信息失败:Err:" + err.Error()
  1113. return
  1114. }
  1115. replaceCalculateTotal += len(predictEdbConfList)
  1116. //替换预测指标的来源指标
  1117. msql = `UPDATE predict_edb_conf SET source_edb_info_id=? WHERE source_edb_info_id=? `
  1118. err = to.Exec(msql, newEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoId).Error
  1119. if err != nil {
  1120. return
  1121. }
  1122. if len(predictEdbConfList) > 0 {
  1123. edbInfoIdList := make([]string, 0)
  1124. for _, v := range predictEdbConfList {
  1125. relationEdbInfoIdList = append(relationEdbInfoIdList, v.PredictEdbInfoId)
  1126. edbInfoIdList = append(edbInfoIdList, fmt.Sprint(v.PredictEdbInfoId))
  1127. }
  1128. logMsg += `涉及到的预测指标id:` + strings.Join(edbInfoIdList, ",") + ";"
  1129. }
  1130. }
  1131. return
  1132. }
  1133. type EdbInfoView struct {
  1134. EdbInfoId int `orm:"column(edb_info_id);pk" gorm:"primaryKey" `
  1135. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  1136. SourceName string `description:"来源名称"`
  1137. Source int `description:"来源id"`
  1138. EdbCode string `description:"指标编码"`
  1139. EdbName string `description:"指标名称"`
  1140. EdbNameSource string `description:"指标名称来源"`
  1141. Frequency string `description:"频率"`
  1142. Unit string `description:"单位"`
  1143. StartDate string `description:"起始日期"`
  1144. EndDate string `description:"终止日期"`
  1145. ClassifyId int `description:"分类id"`
  1146. SysUserId int
  1147. SysUserRealName string
  1148. UniqueCode string `description:"指标唯一编码"`
  1149. CreateTime string
  1150. ModifyTime string
  1151. MinValue float64 `description:"指标最小值"`
  1152. MaxValue float64 `description:"指标最大值"`
  1153. CalculateFormula string `description:"计算公式"`
  1154. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  1155. Sort int `description:"排序字段"`
  1156. IsUpdate int `description:"当天是否已更新,1:未更新,2:已更新"`
  1157. LatestDate string `description:"数据最新日期(实际日期)"`
  1158. LatestValue float64 `description:"数据最新值(实际值)"`
  1159. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  1160. SubSourceName string `description:"子数据来源名称"`
  1161. IndicatorCode string `description:"指标代码"`
  1162. StockCode string `description:"证券代码"`
  1163. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  1164. }
  1165. // EdbInfoFilterDataResp 搜索指标列表数据返回
  1166. type EdbInfoFilterDataResp struct {
  1167. Paging *paging.PagingItem
  1168. List []*EdbInfoList
  1169. }
  1170. // GetEdbInfoFilterList 获取指指标列表数据接口
  1171. func GetEdbInfoFilterList(condition string, pars []interface{}, startSize, pageSize int) (total int64, list []*EdbInfoList, err error) {
  1172. o := global.DmSQL["data"]
  1173. sql := ` SELECT count(1) total FROM edb_info where 1=1 ` + condition + ` ORDER BY edb_info_id DESC `
  1174. err = o.Raw(sql, pars...).Scan(&total).Error
  1175. if err != nil {
  1176. return
  1177. }
  1178. sql = ` SELECT * FROM edb_info where 1=1 ` + condition + ` ORDER BY edb_info_id DESC LIMIT ?,? `
  1179. pars = append(pars, startSize, pageSize)
  1180. err = o.Raw(sql, pars...).Scan(&list).Error
  1181. return
  1182. }
  1183. // SetEdbInfoImageReq 设置指标图片
  1184. type SetEdbInfoImageReq struct {
  1185. EdbInfoId int `description:"指标ID"`
  1186. ImageUrl string `description:"指标图片地址"`
  1187. }
  1188. // GetNextEdbInfoByCondition 根据条件获取下一个指标
  1189. func GetNextEdbInfoByCondition(condition string, pars []interface{}) (item *EdbInfo, err error) {
  1190. o := global.DmSQL["data"]
  1191. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1192. if condition != "" {
  1193. sql += condition
  1194. }
  1195. sql += " ORDER BY sort asc , edb_info_id asc LIMIT 1 "
  1196. err = o.Raw(sql, pars...).First(&item).Error
  1197. return
  1198. }
  1199. // GetNextEdbInfo 根据分类id获取下一个 指标
  1200. func GetNextEdbInfo(classifyId, classifySort, classifyType, edbInfoType int) (item *EdbInfo, err error) {
  1201. o := global.DmSQL["data"]
  1202. sql := ` SELECT b.* FROM edb_classify AS a
  1203. INNER JOIN edb_info AS b ON a.classify_id=b.classify_id
  1204. WHERE (a.sort>? OR (a.sort=? and a.classify_id>?) )
  1205. AND a.classify_type=? AND b.edb_info_type=?
  1206. ORDER BY a.sort ASC,b.sort asc,b.edb_info_id asc
  1207. LIMIT 1 `
  1208. err = o.Raw(sql, classifySort, classifySort, classifyId, classifyType, edbInfoType).Scan(&item).Error
  1209. return
  1210. }
  1211. // GetEdbInfoByEdbCodeList 根据指标code集合获取指标列表
  1212. func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo, err error) {
  1213. num := len(edbCodeList)
  1214. if num <= 0 {
  1215. return
  1216. }
  1217. o := global.DmSQL["data"]
  1218. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) `
  1219. err = o.Raw(sql, source, edbCodeList).Scan(&items).Error
  1220. return
  1221. }
  1222. // GetEdbInfoByConditionCount 根据条件获取指标列表数据总数
  1223. func GetEdbInfoByConditionCount(condition string, pars []interface{}) (count int, err error) {
  1224. o := global.DmSQL["data"]
  1225. sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
  1226. if condition != "" {
  1227. sql += condition
  1228. }
  1229. err = o.Raw(sql, pars...).Scan(&count).Error
  1230. return
  1231. }
  1232. // GetEdbInfoListByCondition 根据条件获取指标列表数据
  1233. func GetEdbInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int, orderDesc string) (items []*EdbInfoList, err error) {
  1234. o := global.DmSQL["data"]
  1235. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1236. if condition != "" {
  1237. sql += condition
  1238. }
  1239. if orderDesc == `` {
  1240. orderDesc = ` ASC `
  1241. }
  1242. sql += ` ORDER BY edb_info_id `
  1243. sql += orderDesc
  1244. sql += ` LIMIT ?,? `
  1245. pars = append(pars, startSize)
  1246. pars = append(pars, pageSize)
  1247. err = o.Raw(sql, pars...).Scan(&items).Error
  1248. return
  1249. }
  1250. // GetEdbInfoListByEdbInfoId
  1251. // @Description: 根据指标id列表获取列表信息
  1252. // @param edbIdList
  1253. // @return items
  1254. // @return err
  1255. func GetEdbInfoListByEdbInfoId(edbIdList []string) (items []*EdbInfo, err error) {
  1256. num := len(edbIdList)
  1257. if num <= 0 {
  1258. return
  1259. }
  1260. o := global.DmSQL["data"]
  1261. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1262. err = o.Raw(sql, edbIdList).Scan(&items).Error
  1263. return
  1264. }
  1265. // GetEdbInfoListByUserId
  1266. // @Description: 根据指标id列表获取列表信息
  1267. // @param userIdList []int
  1268. // @param edbInfoType int
  1269. // @return items
  1270. // @return err
  1271. func GetEdbInfoListByUserId(userIdList []int, edbInfoType int) (items []*EdbInfo, err error) {
  1272. num := len(userIdList)
  1273. if num <= 0 {
  1274. return
  1275. }
  1276. o := global.DmSQL["data"]
  1277. sql := ` SELECT * FROM edb_info WHERE edb_info_type = ? AND sys_user_id in (` + utils.GetOrmInReplace(num) + `) `
  1278. err = o.Raw(sql, edbInfoType, userIdList).Scan(&items).Error
  1279. return
  1280. }
  1281. // ModifyEdbInfoUserIdByCodeList 根据指标code列表修改创建人
  1282. func ModifyEdbInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1283. num := len(edbIdList)
  1284. if num <= 0 {
  1285. return
  1286. }
  1287. o := global.DmSQL["data"]
  1288. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1289. err = o.Exec(sql, userId, userName, edbIdList).Error
  1290. return
  1291. }
  1292. // ModifyEdbInfoUserIdByOldUserId
  1293. // @Description: 根据旧用户id修改新用户id
  1294. // @author: Roc
  1295. // @datetime 2024-03-25 19:17:09
  1296. // @param edbIdList []string
  1297. // @param userId int
  1298. // @param userName string
  1299. // @return err error
  1300. func ModifyEdbInfoUserIdByOldUserId(oldUserIdList []int, edbInfoType, userId int, userName string) (err error) {
  1301. num := len(oldUserIdList)
  1302. if num <= 0 {
  1303. return
  1304. }
  1305. o := global.DmSQL["data"]
  1306. sql := `UPDATE edb_info SET sys_user_id=?,sys_user_real_name=? WHERE sys_user_id in (` + utils.GetOrmInReplace(num) + `) and edb_info_type = ?`
  1307. err = o.Exec(sql, userId, userName, oldUserIdList, edbInfoType).Error
  1308. return
  1309. }
  1310. // MoveEdbChartList 图表/指标信息
  1311. type MoveEdbChartList struct {
  1312. DataId string `description:"指标/图表唯一id"`
  1313. Code string `description:"指标code"`
  1314. Name string `description:"指标/图表名称"`
  1315. NameEn string `description:"指标/图表名称"`
  1316. ClassifyName string `description:"分类名称"`
  1317. ClassifyNameEn string `description:"分类名称"`
  1318. CreateUserId int `description:"创建人id"`
  1319. CreateUserName string `description:"创建人名称"`
  1320. }
  1321. // MoveEdbChartListResp 更改创建人返回数据
  1322. type MoveEdbChartListResp struct {
  1323. Paging *paging.PagingItem
  1324. List []MoveEdbChartList
  1325. }
  1326. type EdbChartClassifyResp struct {
  1327. List []*EdbChartClassify
  1328. }
  1329. type EdbChartClassify struct {
  1330. ClassifyId int
  1331. ClassifyName string
  1332. ParentId int
  1333. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  1334. Child []*EdbChartClassify
  1335. }
  1336. // EdbInfoDataSeasonalResp 指标季节性数据返回
  1337. type EdbInfoDataSeasonalResp struct {
  1338. EdbInfo *EdbInfo
  1339. DataList interface{}
  1340. }
  1341. // SetEdbDataInsertConfigReq 设置插入规则的请求
  1342. type SetEdbDataInsertConfigReq struct {
  1343. EdbInfoId int `description:"指标ID"`
  1344. Date string `description:"日期"`
  1345. Value string `description:"值"`
  1346. }
  1347. // GetEdbInfoByClassifyId 用于分类展示
  1348. func GetEdbInfoByClassifyId(classifyId, edbInfoType, edbType, adminId int, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList []int) (items []*EdbClassifyItems, err error) {
  1349. o := global.DmSQL["data"]
  1350. 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 = ?`
  1351. pars := []interface{}{classifyId, edbInfoType}
  1352. // 如果筛选了指标类型,那么就根据条件来
  1353. if edbType > 0 {
  1354. sql += ` AND edb_type = ? `
  1355. pars = append(pars, edbType)
  1356. }
  1357. // 如果筛选了用户id
  1358. if adminId > 0 {
  1359. sql += ` AND sys_user_id = ? `
  1360. pars = append(pars, adminId)
  1361. }
  1362. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  1363. if noPermissionEdbInfoIdNum > 0 {
  1364. sql += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  1365. pars = append(pars, noPermissionEdbInfoIdList)
  1366. }
  1367. noPermissionClassifyInfoIdNum := len(noPermissionEdbClassifyIdList)
  1368. if noPermissionClassifyInfoIdNum > 0 {
  1369. sql += ` AND classify_id NOT IN (` + utils.GetOrmInReplace(noPermissionClassifyInfoIdNum) + `) `
  1370. pars = append(pars, noPermissionEdbClassifyIdList)
  1371. }
  1372. sql += ` order by sort asc,edb_info_id asc `
  1373. err = o.Raw(sql, pars...).Scan(&items).Error
  1374. return
  1375. }
  1376. type EdbAndClassify struct {
  1377. EdbInfoId int `description:"指标id"`
  1378. EdbCode string `description:"指标code"`
  1379. UniqueCode string `description:"唯一code"`
  1380. EdbName string `description:"指标名称"`
  1381. ClassifyId int `description:"所属分类id"`
  1382. FirstClassifyId int `description:"第1级的分类id"`
  1383. FirstClassifyName string `description:"第1级的分类名称"`
  1384. SecondClassifyId int `description:"第2级的分类id"`
  1385. SecondClassifyName string `description:"第2级的分类名称"`
  1386. }
  1387. // GetEdbInfoAndClassifyListByEdbIdList 根据指标id列表获取 指标及分类信息
  1388. func GetEdbInfoAndClassifyListByEdbIdList(edbIdList []int) (items []*EdbAndClassify, err error) {
  1389. num := len(edbIdList)
  1390. if num <= 0 {
  1391. return
  1392. }
  1393. o := global.DmSQL["data"]
  1394. sql := ` SELECT a.edb_info_id,a.edb_code,a.unique_code,a.edb_name,a.classify_id FROM edb_info AS a
  1395. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1396. err = o.Raw(sql, edbIdList).Scan(&items).Error
  1397. return
  1398. }
  1399. // TraceEdbInfoResp 指标追溯数据返回
  1400. type TraceEdbInfoResp struct {
  1401. EdbInfoId int `description:"指标id"`
  1402. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  1403. EdbName string `description:"指标名称"`
  1404. EdbNameEn string `description:"指标英文名称"`
  1405. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  1406. RuleTitle string `description:"指标规则"`
  1407. RuleTitleEn string `description:"指标规则(英文)"`
  1408. UniqueCode string `description:"唯一编码"`
  1409. ClassifyId int `description:"分类ID"`
  1410. Child []TraceEdbInfoResp `description:"下级来源"`
  1411. IsStop int8 `description:"是否终止"`
  1412. EdbInfo *EdbInfo `description:"指标信息" json:"-"`
  1413. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  1414. }
  1415. // BeforeAndAfterDateDataResp 前后几期数据
  1416. type BeforeAndAfterDateDataResp struct {
  1417. List []*EdbDataList `description:"list"`
  1418. Date string `description:"实际日期"`
  1419. ShowValue string `description:"展示值"`
  1420. }
  1421. // GetEdbInfoAdminList
  1422. func GetEdbInfoAdminList(edbType int) (list []int, err error) {
  1423. o := global.DmSQL["data"]
  1424. sql := ` SELECT sys_user_id FROM edb_info WHERE edb_info_type = ? GROUP BY sys_user_id `
  1425. err = o.Raw(sql, edbType).Scan(&list).Error
  1426. return
  1427. }
  1428. type EdbInfoExistCheckResp struct {
  1429. IndexExist bool `description:"指标是否存在:true,存在,false:不存在"`
  1430. ExistStockCodeArr []string `description:"存在的证券代码"`
  1431. ExistEdbCodeArr []string `description:"存在的指标代码"`
  1432. ExistClassifyId []int `description:"存在的分类id"`
  1433. ExistIndexId []int `description:"存在的指标id"`
  1434. ExistEdbInfo []*EdbInfo `description:"存在的指标"`
  1435. }
  1436. type BatchAddEdbInfoReq struct {
  1437. BatchList []*BatchAddEdbInfo
  1438. }
  1439. type BatchAddEdbInfo struct {
  1440. Source int `description:"来源id"`
  1441. EdbName string `description:"指标名称"`
  1442. Frequency string `description:"频率"`
  1443. Unit string `description:"单位"`
  1444. ClassifyId int `description:"分类id"`
  1445. StockCode string `description:"证券代码"`
  1446. EdbCode string `description:"指标编码"`
  1447. ApiExtraPars string `description:"API额外参数"`
  1448. }
  1449. func GetEdbInfoWsdMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  1450. o := global.DmSQL["data"]
  1451. sql := ``
  1452. tableName := GetEdbDataTableNameAndSubSource(source, subSource)
  1453. 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=? `
  1454. sql = fmt.Sprintf(sql, tableName)
  1455. err = o.Raw(sql, edbCode).Scan(&item).Error
  1456. if err != nil {
  1457. return
  1458. }
  1459. var latest_value float64
  1460. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  1461. sql = fmt.Sprintf(sql, tableName)
  1462. err = o.Raw(sql, edbCode).Scan(&latest_value).Error
  1463. item.LatestValue = latest_value
  1464. return
  1465. }
  1466. // GetEdbInfoByNames 根据名称获取普通的指标
  1467. func GetEdbInfoByNames(edbNames string) (items []*EdbInfoList, err error) {
  1468. o := global.DmSQL["data"]
  1469. sql := ` SELECT * FROM edb_info WHERE edb_name IN (` + edbNames + `) AND edb_info_type = 0 `
  1470. err = o.Raw(sql).Scan(&items).Error
  1471. return
  1472. }
  1473. type EdbInfoSmmExistCheckResp struct {
  1474. EdbInfoExistCheckResp
  1475. ExistAll bool `description:"是否全部重复"`
  1476. }
  1477. // GetEdbBaseInfoList
  1478. // @Description: 获取指标库数据列表
  1479. // @author: Roc
  1480. // @datetime 2024-01-10 14:28:22
  1481. // @param condition string
  1482. // @param pars []interface{}
  1483. // @param orderBy string
  1484. // @param startSize int
  1485. // @param pageSize int
  1486. // @return total int
  1487. // @return items []*BaseRefreshEdbInfo
  1488. // @return err error
  1489. func GetEdbBaseInfoList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRefreshEdbInfo, err error) {
  1490. o := global.DmSQL["data"]
  1491. // 数量汇总
  1492. totalSql := ` SELECT count(1) FROM edb_info WHERE 1=1 `
  1493. if condition != "" {
  1494. totalSql += condition
  1495. }
  1496. err = o.Raw(totalSql, pars...).Scan(&total).Error
  1497. if err != nil {
  1498. return
  1499. }
  1500. // 列表数据
  1501. 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 `
  1502. if condition != "" {
  1503. sql += condition
  1504. }
  1505. if orderBy != "" {
  1506. sql += ` ORDER BY ` + orderBy
  1507. } else {
  1508. sql += ` ORDER BY edb_info_id ASC `
  1509. }
  1510. sql += ` LIMIT ?,? `
  1511. pars = append(pars, startSize, pageSize)
  1512. err = o.Raw(sql, pars...).Scan(&items).Error
  1513. return
  1514. }
  1515. // ModifyEdbInfoUpdateStatus
  1516. // @Description: 修改指标库停更状态
  1517. // @author: Roc
  1518. // @datetime 2024-01-08 16:23:31
  1519. // @param edbIdList []int
  1520. // @param indexCodeList []string
  1521. // @param isStop int
  1522. // @return err error
  1523. func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int, calculateEdbInfoIds []int) (err error) {
  1524. idNum := len(edbIdList)
  1525. if idNum <= 0 {
  1526. return
  1527. }
  1528. o := global.DmSQL["data"].Begin()
  1529. defer func() {
  1530. if err != nil {
  1531. _ = o.Rollback()
  1532. return
  1533. }
  1534. _ = o.Commit()
  1535. }()
  1536. // 更改指标的更新状态
  1537. sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) `
  1538. err = o.Exec(sql, isStop, edbIdList).Error
  1539. if err != nil {
  1540. return
  1541. }
  1542. if len(calculateEdbInfoIds) > 0 {
  1543. // 批量更新相关联的指标ID
  1544. sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
  1545. err = o.Exec(sql, isStop, calculateEdbInfoIds).Error
  1546. if err != nil {
  1547. return
  1548. }
  1549. }
  1550. return
  1551. }
  1552. func GetEdbInfoCount(source int, edbCode string) (count int, err error) {
  1553. o := global.DmSQL["data"]
  1554. sql := ` SELECT COUNT(1) AS count FROM edb_info
  1555. WHERE source=? AND edb_code = ?`
  1556. err = o.Raw(sql, source, edbCode).Scan(&count).Error
  1557. return
  1558. }
  1559. // GetEdbInfoByNameArr 根据名称获取指标
  1560. func GetEdbInfoByNameArr(names []string, edbInfoType int) (items []*EdbInfo, err error) {
  1561. if len(names) == 0 {
  1562. return
  1563. }
  1564. o := global.DmSQL["data"]
  1565. 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)))
  1566. err = o.Raw(sql, names, edbInfoType).Scan(&items).Error
  1567. return
  1568. }
  1569. // GetEdbCodesBySource 根据来源获取指标编码
  1570. func GetEdbCodesBySource(source int) (items []*EdbInfo, err error) {
  1571. o := global.DmSQL["data"]
  1572. sql := ` SELECT edb_info_id, edb_code, unique_code, classify_id FROM edb_info WHERE source = ? `
  1573. err = o.Raw(sql, source).Scan(&items).Error
  1574. return
  1575. }
  1576. // GetAllEdbDataListData
  1577. // @Description: 获取指标的所有数据
  1578. // @author: Roc
  1579. // @datetime 2024-05-07 15:18:27
  1580. // @param edbInfoId int
  1581. // @param source int
  1582. // @param subSource int
  1583. // @param startDataTime string
  1584. // @return dataList []*EdbData
  1585. // @return err error
  1586. func GetAllEdbDataListData(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  1587. // 自有数据需要额外处理(从mongo获取)
  1588. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  1589. return getAllDataByMongo(edbInfoId, source, subSource, startDataTime)
  1590. }
  1591. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  1592. return getThsHfAllDataByMongo(edbInfoId, source, subSource, startDataTime)
  1593. }
  1594. // 默认走mysql
  1595. return getAllDataByMysql(edbInfoId, source, subSource, startDataTime)
  1596. }
  1597. // getAllDataByMysql
  1598. // @Description: 从mysql获取指标的所有数据
  1599. // @author: Roc
  1600. // @datetime 2024-05-07 15:18:41
  1601. // @param edbInfoId int
  1602. // @param source int
  1603. // @param subSource int
  1604. // @param startDataTime string
  1605. // @return dataList []*data_manage.EdbData
  1606. // @return err error
  1607. func getAllDataByMysql(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  1608. dataList = make([]*EdbData, 0)
  1609. var dataCondition string
  1610. var dataPars []interface{}
  1611. dataCondition += ` AND edb_info_id=? `
  1612. dataPars = append(dataPars, edbInfoId)
  1613. // 结束日期
  1614. if startDataTime != "" {
  1615. dataCondition += ` AND data_time > ? `
  1616. dataPars = append(dataPars, startDataTime)
  1617. }
  1618. // 获取列表数据
  1619. dataList, err = GetAllEdbDataListByCondition(dataCondition, dataPars, source, subSource)
  1620. if err != nil {
  1621. return
  1622. }
  1623. return
  1624. }
  1625. // getAllDataByMongo
  1626. // @Description: 从mongo获取指标的所有数据
  1627. // @author: Roc
  1628. // @datetime 2024-05-07 15:18:53
  1629. // @param edbInfoId int
  1630. // @param source int
  1631. // @param subSource int
  1632. // @param startDataTime string
  1633. // @return dataList []*data_manage.EdbData
  1634. // @return err error
  1635. func getAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  1636. dataList = make([]*EdbData, 0)
  1637. mogDataObj := mgo.EdbDataBusiness{}
  1638. // 构建查询条件
  1639. queryConditions := bson.M{
  1640. "edb_info_id": edbInfoId,
  1641. }
  1642. // 开始日期
  1643. dateCondition, err := mgo.BuildDateCondition(startDataTime, "")
  1644. if err != nil {
  1645. return
  1646. }
  1647. if len(dateCondition) > 0 {
  1648. queryConditions["data_time"] = dateCondition
  1649. }
  1650. // 获取列表数据
  1651. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"-data_time"})
  1652. if tmpErr != nil {
  1653. err = tmpErr
  1654. return
  1655. }
  1656. for k, v := range tmpDataList {
  1657. dataList = append(dataList, &EdbData{
  1658. EdbDataId: k + 1,
  1659. EdbInfoId: v.EdbInfoId,
  1660. DataTime: v.DataTime.Format(utils.FormatDate),
  1661. Value: v.Value,
  1662. })
  1663. }
  1664. return
  1665. }
  1666. // GetEdbClassifyIdListBySource 获取普通指标的分类列表
  1667. func GetEdbClassifyIdListBySource(source int) (items []int, err error) {
  1668. o := global.DmSQL["data"]
  1669. sql := `SELECT distinct classify_id FROM edb_info WHERE source = ? and edb_info_type=0`
  1670. err = o.Raw(sql, source).Scan(&items).Error
  1671. return
  1672. }
  1673. // GetEdbInfoByClassifyIdAndSource 用于分类展示
  1674. func GetEdbInfoByClassifyIdAndSource(classifyId, edbInfoType, source int) (items []*EdbClassifyItems, err error) {
  1675. o := global.DmSQL["data"]
  1676. 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 =?`
  1677. pars := []interface{}{classifyId, edbInfoType, source}
  1678. sql += ` order by sort asc,edb_info_id asc `
  1679. err = o.Raw(sql, pars...).Scan(&items).Error
  1680. return
  1681. }
  1682. type ReplaceEdbInfoItem struct {
  1683. OldEdbInfo *EdbInfo
  1684. NewEdbInfo *EdbInfo
  1685. }
  1686. type EdbInfoEditRecord struct {
  1687. EdbInfoId int `description:"指标ID"`
  1688. EdbName string `description:"指标名称"`
  1689. Frequency string `description:"频率"`
  1690. Unit string `description:"单位"`
  1691. ClassifyId int `description:"分类id"`
  1692. CalculateFormula string `description:"计算公式"`
  1693. OperateUserId int `description:"操作人id"`
  1694. OperateUserRealName string `description:"操作人姓名"`
  1695. }
  1696. func ModifyEdbInfoBaseTimeById(edbInfoId int, cTime time.Time) (err error) {
  1697. o := global.DmSQL["data"]
  1698. // 更新修改时间
  1699. sql := ` UPDATE edb_info SET base_modify_time = ? WHERE edb_info_id = ? `
  1700. err = o.Exec(sql, cTime, edbInfoId).Error
  1701. return
  1702. }
  1703. func GetEdbInfoFieldList(cond string, pars []interface{}, fields []string) (items []*EdbInfo, err error) {
  1704. field := " * "
  1705. if len(fields) > 0 {
  1706. field = strings.Join(fields, ",")
  1707. }
  1708. o := global.DmSQL["data"]
  1709. sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s `, field, cond)
  1710. err = o.Raw(sql, pars...).Scan(&items).Error
  1711. return
  1712. }
  1713. // EdbInfoExtra 指标额外数据-extra字段
  1714. type EdbInfoExtra struct {
  1715. ApiExtraPars string `description:"API-额外参数(如同花顺日期序列)"`
  1716. }
  1717. func GetEdbInfoListByCond(condition string, pars []interface{}) (list []*EdbInfoList, err error) {
  1718. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  1719. if condition != "" {
  1720. sql += condition
  1721. }
  1722. sql += ` ORDER BY create_time DESC `
  1723. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&list).Error
  1724. return
  1725. }
  1726. func GetThsHfEdbInfoMaxAndMinInfoByMongo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  1727. mogDataObj := new(mgo.EdbDataThsHf)
  1728. pipeline := []bson.M{
  1729. {"$match": bson.M{"edb_code": edbCode}},
  1730. {"$group": bson.M{
  1731. "_id": nil,
  1732. "min_date": bson.M{"$min": "$data_time"},
  1733. "max_date": bson.M{"$max": "$data_time"},
  1734. "min_value": bson.M{"$min": "$value"},
  1735. "max_value": bson.M{"$max": "$value"},
  1736. }},
  1737. {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
  1738. }
  1739. result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
  1740. if err != nil {
  1741. fmt.Println("EdbDataThsHf getEdbDataThsHfList Err:" + err.Error())
  1742. return
  1743. }
  1744. if !result.MaxDate.IsZero() {
  1745. whereQuery := bson.M{"edb_code": edbCode, "data_time": result.MaxDate}
  1746. selectParam := bson.D{{"value", 1}, {"_id", 0}}
  1747. latestValue, tmpErr := mogDataObj.GetLatestValue(whereQuery, selectParam)
  1748. if tmpErr != nil {
  1749. err = tmpErr
  1750. return
  1751. }
  1752. result.LatestValue = latestValue.Value
  1753. result.EndValue = latestValue.Value
  1754. }
  1755. item = &EdbInfoMaxAndMinInfo{
  1756. MinDate: result.MinDate.Format(utils.FormatDate),
  1757. MaxDate: result.MaxDate.Format(utils.FormatDate),
  1758. MinValue: result.MinValue,
  1759. MaxValue: result.MaxValue,
  1760. LatestValue: result.LatestValue,
  1761. }
  1762. return
  1763. }
  1764. func getThsHfAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (dataList []*EdbData, err error) {
  1765. dataList = make([]*EdbData, 0)
  1766. mogDataObj := mgo.EdbDataThsHf{}
  1767. // 构建查询条件
  1768. queryConditions := bson.M{
  1769. "edb_info_id": edbInfoId,
  1770. }
  1771. // 开始日期
  1772. dateCondition, err := mgo.BuildDateCondition(startDataTime, "")
  1773. if err != nil {
  1774. return
  1775. }
  1776. if len(dateCondition) > 0 {
  1777. queryConditions["data_time"] = dateCondition
  1778. }
  1779. // 获取列表数据
  1780. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"-data_time"})
  1781. if tmpErr != nil {
  1782. err = tmpErr
  1783. return
  1784. }
  1785. for k, v := range tmpDataList {
  1786. dataList = append(dataList, &EdbData{
  1787. EdbDataId: k + 1,
  1788. EdbInfoId: v.EdbInfoId,
  1789. DataTime: v.DataTime.Format(utils.FormatDate),
  1790. Value: v.Value,
  1791. })
  1792. }
  1793. return
  1794. }
  1795. // GetEdbInfoByTypes 根据类型获取所有指标
  1796. func GetEdbInfoByTypes(edbInfoType, edbType int) (items []*EdbClassifyItems, err error) {
  1797. o := global.DmSQL["data"]
  1798. 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`
  1799. err = o.Raw(sql, edbInfoType, edbType).Scan(&items).Error
  1800. return
  1801. }
  1802. // GetIsJoinPermissionEdbInfoIdList
  1803. // @Description: 获取已经加入指标管控的指标id列表
  1804. // @param edbInfoType
  1805. // @param edbType
  1806. // @return list
  1807. // @return err
  1808. func GetIsJoinPermissionEdbInfoIdList(edbInfoType, edbType int) (list []int, err error) {
  1809. pars := make([]interface{}, 0)
  1810. sql := ` SELECT edb_info_id FROM edb_info WHERE 1=1 AND is_join_permission = 1 `
  1811. if edbInfoType >= 0 {
  1812. sql += ` AND edb_info_type = ? `
  1813. pars = append(pars, edbInfoType)
  1814. }
  1815. if edbInfoType > 0 {
  1816. sql += ` AND edb_type = ? `
  1817. pars = append(pars, edbType)
  1818. }
  1819. sql += ` ORDER BY create_time DESC `
  1820. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&list).Error
  1821. return
  1822. }