edb_info.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. package models
  2. import (
  3. "eta/eta_forum_hub/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type EdbInfo struct {
  8. EdbInfoId int `orm:"column(edb_info_id);pk"`
  9. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  10. SourceName string `description:"来源名称"`
  11. Source int `description:"来源id"`
  12. EdbCode string `description:"指标编码"`
  13. EdbName string `description:"指标名称"`
  14. EdbNameEn string `description:"英文指标名称"`
  15. EdbNameSource string `description:"指标名称来源"`
  16. Frequency string `description:"频率"`
  17. Unit string `description:"单位"`
  18. UnitEn string `description:"英文单位"`
  19. StartDate string `description:"起始日期"`
  20. EndDate string `description:"终止日期"`
  21. ClassifyId int `description:"分类id"`
  22. SysUserId int
  23. SysUserRealName string
  24. UniqueCode string `description:"指标唯一编码"`
  25. CreateTime time.Time
  26. ModifyTime time.Time
  27. MinValue float64 `description:"指标最小值"`
  28. MaxValue float64 `description:"指标最大值"`
  29. CalculateFormula string `description:"计算公式"`
  30. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  31. Sort int `description:"排序字段"`
  32. LatestDate string `description:"数据最新日期(实际日期)"`
  33. LatestValue float64 `description:"数据最新值(实际值)"`
  34. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  35. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  36. MoveFrequency string `description:"移动频度"`
  37. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  38. ServerUrl string `description:"服务器地址"`
  39. ChartImage string `description:"图表图片"`
  40. Calendar string `description:"公历/农历" orm:"default(公历);"`
  41. DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  42. ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"`
  43. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  44. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  45. TerminalCode string `description:"终端编码,用于配置在机器上"`
  46. DataUpdateTime string `description:"最近一次数据发生变化的时间"`
  47. ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
  48. SourceIndexName string `description:"数据源中的指标名称"`
  49. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  50. SubSourceName string `description:"子数据来源名称"`
  51. IndicatorCode string `description:"指标代码"`
  52. StockCode string `description:"证券代码"`
  53. Extra string `description:"指标额外配置"`
  54. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  55. }
  56. type EdbInfoFullClassify struct {
  57. *EdbInfo
  58. CorrelationStr string `description:"相关性系数字符串"`
  59. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  60. }
  61. func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
  62. o := orm.NewOrm()
  63. lastId, err = o.Insert(item)
  64. return
  65. }
  66. // 更新指标信息
  67. func (e *EdbInfo) Update(col []string) (err error) {
  68. o := orm.NewOrm()
  69. _, err = o.Update(e, col...)
  70. return
  71. }
  72. type BaseEdbNameItem struct {
  73. EdbInfoId int `description:"指标id"`
  74. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  75. SourceName string `description:"来源名称"`
  76. Source int `description:"来源id"`
  77. EdbCode string `description:"指标编码"`
  78. EdbName string `description:"指标名称"`
  79. Frequency string `description:"频率"`
  80. Unit string `description:"单位"`
  81. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  82. }
  83. type BaseEdbInfoResp struct {
  84. List []*BaseEdbNameItem
  85. }
  86. // 指标检索数据
  87. type EdbInfoSearch struct {
  88. EdbCode string `description:"指标编码"`
  89. StartDate string `description:"起始日期"`
  90. EndDate string `description:"终止日期"`
  91. EdbName string `description:"指标名称"`
  92. Unit string `description:"单位"`
  93. Frequency string `description:"频率"`
  94. DataList []*EdbInfoSearchData
  95. StockList []*StockInfo `description:"时序数据"`
  96. }
  97. type StockInfo struct {
  98. StockCode string
  99. EdbCode string
  100. DataList []*EdbInfoSearchData
  101. }
  102. type EdbInfoSearchData struct {
  103. DataTime string `description:"数据日期"`
  104. Value float64 `description:"数据"`
  105. }
  106. type BaseIndexInfo struct {
  107. IndexName string `description:"数据日期"`
  108. Unit string `description:"单位"`
  109. Frequency string `description:"频率"`
  110. }
  111. type EdbInfoSearchResp struct {
  112. SearchItem *EdbInfoSearch `description:"指标分类"`
  113. Status int `description:"1:数据已存在于弘则数据库,2:新数据,3:数据已存在于弘则数据库,但是当前账号无权限"`
  114. StockSearchList []*EdbInfoSearch
  115. }
  116. func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error) {
  117. o := orm.NewOrm()
  118. sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code=? `
  119. err = o.Raw(sql, source, edbCode).QueryRow(&item)
  120. return
  121. }
  122. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  123. o := orm.NewOrm()
  124. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  125. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  126. return
  127. }
  128. func GetEdbInfoByCondition(condition string, pars []interface{}) (item *EdbInfoList, err error) {
  129. o := orm.NewOrm()
  130. sql := ` SELECT * FROM edb_info WHERE 1=1 `
  131. if condition != "" {
  132. sql += condition
  133. }
  134. err = o.Raw(sql, pars).QueryRow(&item)
  135. return
  136. }
  137. // GetEdbInfoByUniqueCode
  138. // @Description: 根据uniqueCode获取指标详情
  139. // @author: Roc
  140. // @datetime 2024-01-18 13:40:01
  141. // @param uniqueCode string
  142. // @return item *EdbInfo
  143. // @return err error
  144. func GetEdbInfoByUniqueCode(uniqueCode string) (item *EdbInfo, err error) {
  145. o := orm.NewOrm()
  146. sql := ` SELECT * FROM edb_info WHERE unique_code=? `
  147. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  148. return
  149. }
  150. // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
  151. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  152. num := len(edbInfoIdList)
  153. if num <= 0 {
  154. return
  155. }
  156. o := orm.NewOrm()
  157. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  158. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
  159. return
  160. }
  161. func DeleteEdbInfo(edbInfoId int) (err error) {
  162. o := orm.NewOrm()
  163. to, err := o.Begin()
  164. if err != nil {
  165. return
  166. }
  167. defer func() {
  168. if err != nil {
  169. _ = to.Rollback()
  170. } else {
  171. _ = to.Commit()
  172. }
  173. }()
  174. // 删除指标信息
  175. sql := ` DELETE FROM edb_info WHERE edb_info_id=? `
  176. _, err = to.Raw(sql, edbInfoId).Exec()
  177. if err != nil {
  178. return
  179. }
  180. // 删除计算指标的关系
  181. sql = ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id=? `
  182. _, err = to.Raw(sql, edbInfoId).Exec()
  183. return
  184. }
  185. func GetEdbInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  186. o := orm.NewOrm()
  187. sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
  188. if condition != "" {
  189. sql += condition
  190. }
  191. err = o.Raw(sql, pars).QueryRow(&count)
  192. return
  193. }
  194. type EditEdbInfoReq struct {
  195. EdbInfoId int `description:"指标ID"`
  196. EdbName string `description:"指标名称"`
  197. Frequency string `description:"频率"`
  198. Unit string `description:"单位"`
  199. ClassifyId int `description:"分类id"`
  200. CalculateFormula string `description:"计算公式"`
  201. }
  202. type EditEdbEnInfoReq struct {
  203. EdbInfoId int `description:"指标ID"`
  204. EdbNameEn string `description:"英文指标名称"`
  205. UnitEn string `description:"英文单位"`
  206. }
  207. func ModifyEdbInfo(item *EditEdbInfoReq) (err error) {
  208. o := orm.NewOrm()
  209. sql := ` UPDATE edb_info
  210. SET
  211. edb_name =?,
  212. edb_name_source =?,
  213. frequency = ?,
  214. unit = ?,
  215. classify_id = ?,
  216. modify_time = NOW()
  217. WHERE edb_info_id = ?`
  218. _, err = o.Raw(sql, item.EdbName, item.EdbName, item.Frequency, item.Unit, item.ClassifyId, item.EdbInfoId).Exec()
  219. return
  220. }
  221. // ModifyEdbEnInfo 修改指标英文信息
  222. func ModifyEdbEnInfo(item *EditEdbEnInfoReq) (err error) {
  223. o := orm.NewOrm()
  224. sql := ` UPDATE edb_info
  225. SET
  226. edb_name_en =?,
  227. unit_en = ?,
  228. modify_time = NOW()
  229. WHERE edb_info_id = ?`
  230. _, err = o.Raw(sql, item.EdbNameEn, item.UnitEn, item.EdbInfoId).Exec()
  231. return
  232. }
  233. type EdbInfoList struct {
  234. EdbInfoId int `orm:"column(edb_info_id);pk"`
  235. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  236. SourceName string `description:"来源名称"`
  237. Source int `description:"来源id"`
  238. EdbCode string `description:"指标编码"`
  239. EdbNameEn string `description:"英文指标名称"`
  240. EdbName string `description:"指标名称"`
  241. Frequency string `description:"频率"`
  242. FrequencyEn string `description:"英文频率"`
  243. Unit string `description:"单位"`
  244. UnitEn string `description:"英文单位"`
  245. StartDate string `description:"起始日期"`
  246. EndDate string `description:"终止日期"`
  247. LatestDate string `description:"数据最新日期(实际日期)"`
  248. LatestValue float64 `description:"数据最新值(实际值)"`
  249. EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
  250. ClassifyId int `description:"分类id"`
  251. UniqueCode string `description:"指标唯一编码"`
  252. SysUserId int `description:"创建人id"`
  253. SysUserRealName string `description:"创建人姓名"`
  254. ModifyTime string `description:"最新修改时间"`
  255. CreateTime string `description:"创建时间"`
  256. EdbNameAlias string `json:"-" description:"指标名称,别名"`
  257. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  258. ChartImage string `description:"图表图片"`
  259. RuleType int `description:"预测规则,1:最新,2:固定值"`
  260. FixedValue float64 `description:"固定值"`
  261. DataList []*EdbData `description:"实际指标数据"`
  262. PredictDataList []*EdbData `description:"预测指标数据"`
  263. IsEnEdb bool `description:"是否展示英文标识"`
  264. DataInsertConfig EdbDataInsertConfigItem `description:"指标数据插入配置"`
  265. DataDateType string `description:"数据日期类型,枚举值:交易日、自然日"`
  266. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  267. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  268. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  269. SubSourceName string `description:"子数据来源名称"`
  270. IndicatorCode string `description:"指标代码"`
  271. StockCode string `description:"证券代码"`
  272. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  273. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  274. HaveOperaAuth bool `description:"是否有数据权限,默认:false"`
  275. }
  276. type EdbDataInsertConfigItem struct {
  277. Date string `description:"插入的日期"`
  278. RealDate string `description:"实际最晚的日期"`
  279. Value string `description:"插入的值"`
  280. }
  281. type EdbData struct {
  282. EdbDataId int `orm:"column(edb_data_id);pk"`
  283. EdbInfoId int
  284. DataTime string
  285. Value float64
  286. }
  287. type EdbInfoListResp struct {
  288. Item *EdbInfoList
  289. }