base_from_usda_fas.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type BaseFromUsdaFasIndex struct {
  9. BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"`
  10. ClassifyId int
  11. IndexCode string
  12. IndexName string
  13. Frequency string
  14. Unit string
  15. Sort int
  16. StartDate string `description:"开始日期"`
  17. EndDate string `description:"结束日期"`
  18. EndValue float64
  19. CreateTime time.Time
  20. ModifyTime time.Time
  21. }
  22. type BaseFromUsdaFasIndexList struct {
  23. BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"`
  24. ClassifyId int
  25. Interface string
  26. EdbInfoId int
  27. EdbUniqueCode string `description:"指标库唯一编码"`
  28. EdbClassifyId int `description:"指标库分类ID"`
  29. StartDate string
  30. EndDate string
  31. EndValue float64
  32. IndexCode string
  33. IndexName string
  34. Frequency string
  35. Unit string
  36. Sort int
  37. CreateTime string
  38. ModifyTime string
  39. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  40. DataList []*BaseFromUsdaFasData
  41. Paging *paging.PagingItem `description:"分页数据"`
  42. }
  43. type BaseFromUsdaFasIndexSearchList struct {
  44. List []*BaseFromUsdaFasIndexList
  45. Paging *paging.PagingItem `description:"分页数据"`
  46. }
  47. type UsdaFasSingleDataResp struct {
  48. BaseFromUsdaFasIndexId int
  49. ClassifyId int
  50. EdbInfoId int
  51. IndexCode string
  52. IndexName string
  53. Frequency string
  54. Unit string
  55. StartTime string
  56. CreateTime string
  57. ModifyTime string
  58. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  59. Data []*UsdaFasSingleData
  60. }
  61. type UsdaFasSingleData struct {
  62. Value string `orm:"column(value)" description:"日期"`
  63. DataTime string `orm:"column(data_time)" description:"值"`
  64. }
  65. func GetUsdaFasIndexByClassifyId(classifyId int) (items []*BaseFromUsdaFasIndex, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := ` SELECT base_from_usda_fas_index_id, classify_id, index_code, index_name FROM base_from_usda_fas_index WHERE classify_id=? ORDER BY sort ASC, base_from_usda_fas_index_id ASC `
  68. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  69. return
  70. }
  71. func GetUsdaFasIndex(condition string, pars interface{}) (items []*BaseFromUsdaFasIndexList, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. sql := ` SELECT * FROM base_from_usda_fas_index WHERE 1=1 `
  74. if condition != "" {
  75. sql += condition
  76. }
  77. sql += ` ORDER BY sort ASC, base_from_usda_fas_index_id asc`
  78. _, err = o.Raw(sql, pars).QueryRows(&items)
  79. return
  80. }
  81. func GetUsdaFasIndexPage(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromUsdaFasIndexList, err error) {
  82. o := orm.NewOrmUsingDB("data")
  83. sql := ` SELECT * FROM base_from_usda_fas_index WHERE 1=1 `
  84. if condition != "" {
  85. sql += condition
  86. }
  87. sql += ` ORDER BY sort ASC, base_from_usda_fas_index_id asc LIMIT ?,?`
  88. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  89. return
  90. }
  91. func GetUsdaFasIndexPageCount(condition string, pars interface{}) (count int, err error) {
  92. o := orm.NewOrmUsingDB("data")
  93. sql := ` SELECT COUNT(1) AS count FROM base_from_usda_fas_index WHERE 1=1 `
  94. if condition != "" {
  95. sql += condition
  96. }
  97. err = o.Raw(sql, pars).QueryRow(&count)
  98. return
  99. }
  100. func GetUsdaFasIndexDataCount(indexCode string) (count int, err error) {
  101. o := orm.NewOrmUsingDB("data")
  102. sql := ` SELECT COUNT(1) AS count FROM base_from_usda_fas_data WHERE index_code=? `
  103. err = o.Raw(sql, indexCode).QueryRow(&count)
  104. return
  105. }
  106. func GetUsdaFasIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromUsdaFasData, err error) {
  107. o := orm.NewOrmUsingDB("data")
  108. sql := ` SELECT * FROM base_from_usda_fas_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) and data_time >=? and data_time <? ORDER BY data_time DESC `
  109. _, err = o.Raw(sql, indexCodes, startDate, endDate).QueryRows(&items)
  110. return
  111. }
  112. func GetUsdaFasIndexDataTimePageByCodes(indexCodes []string, startSize, pageSize int) (dataTimes []string, err error) {
  113. o := orm.NewOrmUsingDB("data")
  114. sql := ` SELECT data_time FROM base_from_usda_fas_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
  115. _, err = o.Raw(sql, indexCodes, startSize, pageSize).QueryRows(&dataTimes)
  116. return
  117. }
  118. func GetUsdaFasIndexDataTimePageCount(indexCodes []string) (count int, err error) {
  119. o := orm.NewOrmUsingDB("data")
  120. sql := ` SELECT COUNT(DISTINCT data_time) AS count FROM base_from_usda_fas_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) `
  121. err = o.Raw(sql, indexCodes).QueryRow(&count)
  122. return
  123. }
  124. func GetUsdaFasIndexDataByCodes(indexCode []string) (items []*BaseFromUsdaFasData, err error) {
  125. if len(indexCode) == 0 {
  126. return
  127. }
  128. o := orm.NewOrmUsingDB("data")
  129. sql := ` SELECT * FROM base_from_usda_fas_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  130. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  131. return
  132. }
  133. // GetUsdaFasByConditionAndFrequency 根据条件获取涌益咨询指标列表
  134. func GetUsdaFasByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromUsdaFasIndex, err error) {
  135. o := orm.NewOrmUsingDB("data")
  136. sql := ` SELECT * FROM base_from_usda_fas_index WHERE 1=1 `
  137. if condition != "" {
  138. sql += condition
  139. }
  140. sql += ` AND frequency=?`
  141. sql += ` ORDER BY sort ASC, base_from_usda_fas_index_id ASC`
  142. _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
  143. return
  144. }
  145. func GetUsdaFasFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) {
  146. sql := `SELECT DISTINCT frequency FROM base_from_usda_fas_index WHERE 1=1 `
  147. if condition != "" {
  148. sql += condition
  149. }
  150. sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') `
  151. o := orm.NewOrmUsingDB("data")
  152. _, err = o.Raw(sql, pars...).QueryRows(&items)
  153. return
  154. }
  155. // GetUsdaFasDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
  156. func GetUsdaFasDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
  157. if len(indexIdList) == 0 {
  158. return
  159. }
  160. o := orm.NewOrmUsingDB("data")
  161. sql := ` SELECT DISTINCT data_time FROM base_from_usda_fas_data WHERE base_from_usda_fas_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
  162. _, err = o.Raw(sql, indexIdList).QueryRows(&items)
  163. return
  164. }
  165. type BaseFromUsdaFasData struct {
  166. BaseFromUsdaFasDataId int `orm:"column(base_from_usda_fas_data_id);pk"`
  167. BaseFromUsdaFasIndexId int
  168. IndexCode string
  169. DataTime string
  170. Value string
  171. CreateTime string
  172. ModifyTime string
  173. DataTimestamp int64
  174. }
  175. type BaseFromUsdaFasIndexSearchItem struct {
  176. BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"`
  177. ClassifyId int
  178. ParentClassifyId int
  179. IndexCode string
  180. IndexName string
  181. }
  182. // BatchCheckUsdaFasEdbReq 指标数据结构体
  183. type BatchCheckUsdaFasEdbReq struct {
  184. //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
  185. Frequencies string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  186. Keyword string `description:"关键字"`
  187. ClassifyIds string `description:"所选品种id列表"`
  188. ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
  189. TradeCodeList string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  190. }
  191. // GetUsdaFasItemList 模糊查询UsdaFas数据库指标列表
  192. func GetUsdaFasItemList(condition string) (items []*BaseFromUsdaFasIndexSearchItem, err error) {
  193. o := orm.NewOrmUsingDB("data")
  194. sql := "SELECT * FROM base_from_usda_fas_index WHERE 1=1"
  195. if condition != "" {
  196. sql += condition
  197. }
  198. _, err = o.Raw(sql).QueryRows(&items)
  199. return
  200. }
  201. func GetUsdaFasIndexDataByCode(indexCode string) (list []*BaseFromUsdaFasData, err error) {
  202. o := orm.NewOrmUsingDB("data")
  203. sql := `SELECT * FROM base_from_usda_fas_data WHERE index_code=? `
  204. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  205. return
  206. }
  207. func GetBaseFromUsdaFasIndexByIndexCode(indexCode string) (list *BaseFromUsdaFasIndex, err error) {
  208. o := orm.NewOrmUsingDB("data")
  209. sql := ` SELECT * FROM base_from_usda_fas_index WHERE index_code=? `
  210. err = o.Raw(sql, indexCode).QueryRow(&list)
  211. return
  212. }
  213. type BaseFromUsdaFasIndexType struct {
  214. Type2 string `orm:"column(type_2)"`
  215. Type3 string `orm:"column(type_3)"`
  216. }
  217. // Update 更新UsdaFas指标基础信息
  218. func (item *BaseFromUsdaFasIndex) Update(cols []string) (err error) {
  219. o := orm.NewOrmUsingDB("data")
  220. _, err = o.Update(item, cols...)
  221. return
  222. }
  223. // EditUsdaFasIndexInfoResp 新增指标的返回
  224. type EditUsdaFasIndexInfoResp struct {
  225. BaseFromUsdaFasIndexId int `description:"指标ID"`
  226. IndexCode string `description:"指标code"`
  227. }
  228. type UsdaFasIndexSource2EdbReq struct {
  229. EdbCode string
  230. EdbName string
  231. Frequency string
  232. Unit string
  233. ClassifyId int
  234. AdminId int
  235. AdminRealName string
  236. }
  237. func GetUsdaFasFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
  238. o := orm.NewOrmUsingDB("data")
  239. sql := ` SELECT frequency FROM base_from_usda_fas_index WHERE classify_id = ? `
  240. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  241. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  242. return
  243. }