base_from_yongyi.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package data_manage
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "github.com/shopspring/decimal"
  6. "gorm.io/gorm"
  7. "time"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. type BaseFromYongyiIndex struct {
  11. YongyiIndexId int `orm:"column(yongyi_index_id);pk"`
  12. ClassifyId int
  13. IndexCode string
  14. IndexName string
  15. Frequency string
  16. Unit string
  17. Sort int
  18. CreateTime time.Time
  19. ModifyTime time.Time
  20. }
  21. type BaseFromYongyiIndexList struct {
  22. YongyiIndexId int `gorm:"column:yongyi_index_id;primaryKey"`
  23. ClassifyId int
  24. Interface string
  25. EdbInfoId int
  26. EdbUniqueCode string `description:"指标库唯一编码"`
  27. EdbClassifyId int `description:"指标库分类ID"`
  28. IndexCode string
  29. IndexName string
  30. Frequency string
  31. Unit string
  32. Sort int
  33. CreateTime string
  34. ModifyTime string
  35. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  36. DataList []*BaseFromYongyiData `gorm:"-"`
  37. Paging *paging.PagingItem `description:"分页数据" gorm:"-"`
  38. }
  39. func (m *BaseFromYongyiIndexList) AfterFind(tx *gorm.DB) (err error) {
  40. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  41. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  42. return
  43. }
  44. type YongyiSingleDataResp struct {
  45. YongyiIndexId int
  46. ClassifyId int
  47. EdbInfoId int
  48. IndexCode string
  49. IndexName string
  50. Frequency string
  51. Unit string
  52. StartTime string
  53. CreateTime string
  54. ModifyTime string
  55. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  56. Data []*YongyiSingleData
  57. }
  58. type YongyiSingleData struct {
  59. Value string `orm:"column(value)" description:"日期"`
  60. DataTime string `orm:"column(data_time)" description:"值"`
  61. }
  62. func GetYongyiIndexByClassifyId(classifyId int) (items []*BaseFromYongyiIndex, err error) {
  63. o := global.DbMap[utils.DbNameIndex]
  64. sql := ` SELECT yongyi_index_id, classify_id, index_code, index_name FROM base_from_yongyi_index WHERE classify_id=? ORDER BY sort ASC, yongyi_index_id ASC `
  65. err = o.Raw(sql, classifyId).Find(&items).Error
  66. return
  67. }
  68. func GetYongyiIndex(condition string, pars []interface{}) (items []*BaseFromYongyiIndexList, err error) {
  69. o := global.DbMap[utils.DbNameIndex]
  70. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  71. if condition != "" {
  72. sql += condition
  73. }
  74. sql += ` ORDER BY sort ASC, yongyi_index_id asc`
  75. err = o.Raw(sql, pars...).Find(&items).Error
  76. return
  77. }
  78. func GetYongyiIndexDataCount(indexCode string) (count int, err error) {
  79. o := global.DbMap[utils.DbNameIndex]
  80. sql := ` SELECT COUNT(1) AS count FROM base_from_yongyi_data WHERE index_code=? `
  81. err = o.Raw(sql, indexCode).Scan(&count).Error
  82. return
  83. }
  84. func GetYongyiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromYongyiData, err error) {
  85. o := global.DbMap[utils.DbNameIndex]
  86. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  87. err = o.Raw(sql, indexCode, startSize, pageSize).Find(&items).Error
  88. return
  89. }
  90. func GetYongyiIndexDataByCodes(indexCode []string) (items []*BaseFromYongyiData, err error) {
  91. if len(indexCode) == 0 {
  92. return
  93. }
  94. o := global.DbMap[utils.DbNameIndex]
  95. sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  96. err = o.Raw(sql, indexCode).Find(&items).Error
  97. return
  98. }
  99. // GetYongyiByConditionAndFrequency 根据条件获取涌益咨询指标列表
  100. func GetYongyiByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromYongyiIndex, err error) {
  101. o := global.DbMap[utils.DbNameIndex]
  102. sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 `
  103. if condition != "" {
  104. sql += condition
  105. }
  106. sql += ` AND frequency=?`
  107. sql += ` ORDER BY sort ASC, yongyi_index_id ASC`
  108. err = o.Raw(sql, pars, frequency).Find(&items).Error
  109. return
  110. }
  111. func GetYongyiFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) {
  112. sql := `SELECT DISTINCT frequency FROM base_from_yongyi_index WHERE 1=1 `
  113. if condition != "" {
  114. sql += condition
  115. }
  116. sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') `
  117. o := global.DbMap[utils.DbNameIndex]
  118. err = o.Raw(sql, pars...).Find(&items).Error
  119. return
  120. }
  121. // GetYongyiDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  122. func GetYongyiDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  123. if len(indexIdList) == 0 {
  124. return
  125. }
  126. o := global.DbMap[utils.DbNameIndex]
  127. sql := ` SELECT DISTINCT data_time FROM base_from_yongyi_data WHERE yongyi_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  128. err = o.Raw(sql, indexIdList).Find(&items).Error
  129. for i := range items {
  130. items[i] = utils.GormDateStrToDateStr(items[i])
  131. }
  132. return
  133. }
  134. type BaseFromYongyiData struct {
  135. YongyiDataId int `gorm:"column:yongyi_data_id;primaryKey"`
  136. YongyiIndexId int
  137. IndexCode string
  138. DataTime string
  139. Value decimal.Decimal
  140. CreateTime string
  141. ModifyTime string
  142. DataTimestamp int64 `gorm:"column:data_timestamp"`
  143. }
  144. func (m *BaseFromYongyiData) AfterFind(tx *gorm.DB) (err error) {
  145. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  146. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  147. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  148. return
  149. }
  150. type BaseFromYongyiIndexSearchItem struct {
  151. YongyiIndexId int `gorm:"column:yongyi_index_id;primaryKey"`
  152. ClassifyId int
  153. ParentClassifyId int
  154. IndexCode string
  155. IndexName string
  156. }
  157. // GetYongyiItemList 模糊查询Yongyi数据库指标列表
  158. func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) {
  159. o := global.DbMap[utils.DbNameIndex]
  160. sql := "SELECT * FROM base_from_yongyi_index WHERE 1=1"
  161. if condition != "" {
  162. sql += condition
  163. }
  164. err = o.Raw(sql).Find(&items).Error
  165. return
  166. }
  167. func GetYongyiIndexDataByCode(indexCode string) (list []*BaseFromYongyiData, err error) {
  168. o := global.DbMap[utils.DbNameIndex]
  169. sql := `SELECT * FROM base_from_yongyi_data WHERE index_code=? `
  170. err = o.Raw(sql, indexCode).Find(&list).Error
  171. return
  172. }
  173. func GetBaseFromYongyiIndexByIndexCode(indexCode string) (list *BaseFromYongyiIndex, err error) {
  174. o := global.DbMap[utils.DbNameIndex]
  175. sql := ` SELECT * FROM base_from_yongyi_index WHERE index_code=? `
  176. err = o.Raw(sql, indexCode).First(&list).Error
  177. return
  178. }
  179. type BaseFromYongyiIndexType struct {
  180. Type2 string `gorm:"column:type_2"`
  181. Type3 string `gorm:"column:type_3"`
  182. }
  183. // Update 更新Yongyi指标基础信息
  184. func (item *BaseFromYongyiIndex) Update(cols []string) (err error) {
  185. o := global.DbMap[utils.DbNameIndex]
  186. err = o.Select(cols).Updates(item).Error
  187. return
  188. }
  189. // EditYongyiIndexInfoResp 新增指标的返回
  190. type EditYongyiIndexInfoResp struct {
  191. YongyiIndexId int `description:"指标ID"`
  192. IndexCode string `description:"指标code"`
  193. }