base_from_bloomberg_index.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. // BaseFromBloombergIndex 彭博原始指标表
  11. type BaseFromBloombergIndex struct {
  12. BaseFromBloombergIndexId int `orm:"column(base_from_bloomberg_index_id);pk" gorm:"primaryKey" `
  13. IndexCode string `description:"指标编码"`
  14. IndexName string `description:"指标名称"`
  15. Unit string `description:"单位"`
  16. Source int `description:"数据来源"`
  17. Frequency string `description:"频度"`
  18. StartDate time.Time `description:"开始日期"`
  19. EndDate time.Time `description:"结束日期"`
  20. Describe string `description:"指标描述"`
  21. Sort int `description:"排序"`
  22. IsStop int `description:"是否停更:0-否;1-停更"`
  23. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  24. TerminalCode string `description:"所属终端编码"`
  25. FilePath string `description:"文件存储路径"`
  26. CreateTime time.Time `description:"创建时间"`
  27. ModifyTime time.Time `description:"修改时间"`
  28. }
  29. var BaseFromBloombergIndexCols = struct {
  30. BaseFromBloombergIndexId string
  31. IndexCode string
  32. IndexName string
  33. Unit string
  34. Source string
  35. Frequency string
  36. StartDate string
  37. EndDate string
  38. Describe string
  39. Sort string
  40. IsStop string
  41. EdbExist string
  42. TerminalCode string
  43. FilePath string
  44. CreateTime string
  45. ModifyTime string
  46. }{
  47. BaseFromBloombergIndexId: "base_from_bloomberg_index_id",
  48. IndexCode: "index_code",
  49. IndexName: "index_name",
  50. Unit: "unit",
  51. Source: "source",
  52. Frequency: "frequency",
  53. StartDate: "start_date",
  54. EndDate: "end_date",
  55. Describe: "describe",
  56. Sort: "sort",
  57. IsStop: "is_stop",
  58. EdbExist: "edb_exist",
  59. TerminalCode: "terminal_code",
  60. FilePath: "file_path",
  61. CreateTime: "create_time",
  62. ModifyTime: "modify_time",
  63. }
  64. func (m *BaseFromBloombergIndex) TableName() string {
  65. return "base_from_bloomberg_index"
  66. }
  67. func (m *BaseFromBloombergIndex) PrimaryId() string {
  68. return BaseFromBloombergIndexCols.BaseFromBloombergIndexId
  69. }
  70. func (m *BaseFromBloombergIndex) Create() (err error) {
  71. err = global.DmSQL["data"].Create(m).Error
  72. return
  73. }
  74. func (m *BaseFromBloombergIndex) CreateMulti(items []*BaseFromBloombergIndex) (err error) {
  75. if len(items) == 0 {
  76. return
  77. }
  78. err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
  79. return
  80. }
  81. func (m *BaseFromBloombergIndex) Update(cols []string) (err error) {
  82. o := global.DmSQL["data"]
  83. err = o.Select(cols).Updates(m).Error
  84. return
  85. }
  86. func (m *BaseFromBloombergIndex) Del() (err error) {
  87. o := global.DmSQL["data"]
  88. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  89. err = o.Exec(sql, m.BaseFromBloombergIndexId).Error
  90. return
  91. }
  92. func (m *BaseFromBloombergIndex) MultiDel(menuIds []int) (err error) {
  93. if len(menuIds) == 0 {
  94. return
  95. }
  96. o := global.DmSQL["data"]
  97. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  98. err = o.Exec(sql, menuIds).Error
  99. return
  100. }
  101. func (m *BaseFromBloombergIndex) GetItemById(id int) (item *BaseFromBloombergIndex, err error) {
  102. o := global.DmSQL["data"]
  103. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  104. err = o.Raw(sql, id).First(&item).Error
  105. return
  106. }
  107. func (m *BaseFromBloombergIndex) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *BaseFromBloombergIndex, err error) {
  108. o := global.DmSQL["data"]
  109. order := ``
  110. if orderRule != "" {
  111. order = ` ORDER BY ` + orderRule
  112. }
  113. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  114. err = o.Raw(sql, pars...).First(&item).Error
  115. return
  116. }
  117. func (m *BaseFromBloombergIndex) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  118. o := global.DmSQL["data"]
  119. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  120. err = o.Raw(sql, pars...).Scan(&count).Error
  121. return
  122. }
  123. func (m *BaseFromBloombergIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, limit int) (items []*BaseFromBloombergIndex, err error) {
  124. o := global.DmSQL["data"]
  125. fields := strings.Join(fieldArr, ",")
  126. if len(fieldArr) == 0 {
  127. fields = `*`
  128. }
  129. order := `ORDER BY create_time DESC`
  130. if orderRule != "" {
  131. order = ` ORDER BY ` + orderRule
  132. }
  133. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  134. if limit > 0 {
  135. sql += fmt.Sprintf(` LIMIT %d`, limit)
  136. }
  137. err = o.Raw(sql, pars...).Scan(&items).Error
  138. return
  139. }
  140. func (m *BaseFromBloombergIndex) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BaseFromBloombergIndex, err error) {
  141. o := global.DmSQL["data"]
  142. fields := strings.Join(fieldArr, ",")
  143. if len(fieldArr) == 0 {
  144. fields = `*`
  145. }
  146. order := `ORDER BY create_time DESC`
  147. if orderRule != "" {
  148. order = ` ORDER BY ` + orderRule
  149. }
  150. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  151. pars = append(pars, startSize)
  152. pars = append(pars, pageSize)
  153. err = o.Raw(sql, pars...).Scan(&items).Error
  154. return
  155. }
  156. // BaseFromBloombergIndexItem 彭博原始指标信息
  157. type BaseFromBloombergIndexItem struct {
  158. BaseFromBloombergIndexId int
  159. IndexCode string `description:"指标编码"`
  160. IndexName string `description:"指标名称"`
  161. Unit string `description:"单位"`
  162. Source int `description:"数据来源"`
  163. Frequency string `description:"频度"`
  164. StartDate string `description:"开始日期"`
  165. EndDate string `description:"结束日期"`
  166. Describe string `description:"指标描述"`
  167. Sort int `description:"排序"`
  168. IsStop int `description:"是否停更:0-否;1-停更"`
  169. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  170. CreateTime string `description:"创建时间"`
  171. ModifyTime string `description:"修改时间"`
  172. EdbInfoId int `description:"指标库ID"`
  173. EdbUniqueCode string `description:"指标库唯一编码"`
  174. EdbClassifyId int `description:"指标库分类ID"`
  175. }
  176. func FormatBaseFromBloombergIndex2Item(origin *BaseFromBloombergIndex) (item *BaseFromBloombergIndexItem) {
  177. if origin == nil {
  178. return
  179. }
  180. item = new(BaseFromBloombergIndexItem)
  181. item.BaseFromBloombergIndexId = origin.BaseFromBloombergIndexId
  182. item.IndexCode = origin.IndexCode
  183. item.IndexName = origin.IndexName
  184. item.Unit = origin.Unit
  185. item.Source = origin.Source
  186. item.Frequency = origin.Frequency
  187. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  188. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  189. item.Describe = origin.Describe
  190. item.Sort = origin.Sort
  191. item.IsStop = origin.IsStop
  192. //item.EdbExist = origin.EdbExist
  193. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  194. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  195. return
  196. }
  197. // BloombergSourceListReq 指标列表筛选
  198. type BloombergSourceListReq struct {
  199. PageSize int `form:"PageSize"`
  200. CurrentIndex int `form:"CurrentIndex"`
  201. Frequency string `form:"Frequency" description:"频度"`
  202. Keywords string `form:"Keywords" description:"指标ID/指标名称"`
  203. ListAll bool `form:"ListAll" description:"列表全选"`
  204. SortField int `form:"SortField" description:"排序字段: 0-默认; 1-开始时间; 2-最新时间; 3-更新时间"`
  205. SortRule int `form:"SortRule" description:"排序方式: 0-默认; 1-正序; 2-倒序"`
  206. }
  207. // BloombergSourceListResp 指标列表响应体
  208. type BloombergSourceListResp struct {
  209. List []*BaseFromBloombergIndexItem
  210. Paging *paging.PagingItem `description:"分页数据"`
  211. }
  212. // UpdateEdbExist 标记已添加指标库
  213. func (m *BaseFromBloombergIndex) UpdateEdbExist(indexCode string) (err error) {
  214. o := global.DmSQL["data"]
  215. sql := fmt.Sprintf(`UPDATE %s SET %s = ? WHERE %s = ? LIMIT 1`, m.TableName(), BaseFromBloombergIndexCols.EdbExist, BaseFromBloombergIndexCols.IndexCode)
  216. err = o.Exec(sql, 1, indexCode).Error
  217. return
  218. }
  219. // BloombergSourceBatchAddCheckReq Bloomberg批量添加校验
  220. type BloombergSourceBatchAddCheckReq struct {
  221. BloombergSourceListReq
  222. IndexCodes []string `form:"IndexCodes" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  223. }