base_from_ly_index.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Package data_manage
  2. // @Author gmy 2024/8/7 9:38:00
  3. package data_manage
  4. import (
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type BaseFromLyIndex struct {
  9. BaseFromLyIndexId int `orm:"column(base_from_ly_index_id);pk" description:"指标ID"`
  10. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  11. ModifyTime string `orm:"column(modify_time)" description:"修改时间"`
  12. BaseFromLyClassifyId int `orm:"column(base_from_ly_classify_id)" description:"原始数据指标分类id"`
  13. IndexCode string `orm:"column(index_code)" description:"指标编码"`
  14. IndexName string `orm:"column(index_name)" description:"指标名称"`
  15. Frequency string `orm:"column(frequency)" description:"频度"`
  16. Unit string `orm:"column(unit)" description:"单位"`
  17. EdbExist int `orm:"column(edb_exist)" description:"指标库是否已添加:0-否;1-是"`
  18. }
  19. // 在 init 函数中注册模型
  20. func init() {
  21. orm.RegisterModel(new(BaseFromLyIndex))
  22. }
  23. type BaseFromLyIndexPage struct {
  24. List []*BaseFromLyIndex `description:"指标列表"`
  25. Paging *paging.PagingItem `description:"分页数据"`
  26. }
  27. type BaseFromLyIndexBatchAddCheckReq struct {
  28. IndexCodes []string `form:"IndexCodes" description:"指标编码列表"`
  29. }
  30. type BaseFromLyIndexNameCheck struct {
  31. IndexCode string `from:"IndexCode" description:"指标编码"`
  32. IndexName string `from:"IndexName" description:"指标名称"`
  33. }
  34. type NameCheckResult struct {
  35. IndexCode string `from:"EdbCode" description:"edb编码"`
  36. IndexName string `from:"EdbName" description:"edb名称"`
  37. Exist bool
  38. }
  39. // GetLyIndexByClassifyIds 通过分类ids查询指标列表
  40. func GetLyIndexByClassifyIds(classifyIds []int) (items []*BaseFromLyIndex, err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. sql := `SELECT * FROM base_from_ly_index WHERE base_from_ly_classify_id IN (?)`
  43. _, err = o.Raw(sql, classifyIds).QueryRows(&items)
  44. return
  45. }
  46. // GetLyIndexCount 获取指标总数
  47. func GetLyIndexCount(searchParam string) (count int, err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := `SELECT count(*) FROM base_from_ly_index WHERE 1=1`
  50. var params []interface{}
  51. if searchParam != "" {
  52. sql += ` AND (index_name LIKE ? OR index_code = ?)`
  53. params = append(params, "%"+searchParam+"%", searchParam)
  54. }
  55. sql += ` ORDER BY base_from_ly_index_id DESC`
  56. err = o.Raw(sql, params...).QueryRow(&count)
  57. return
  58. }
  59. // GetLyIndexPage 获取指标列表
  60. func GetLyIndexPage(searchParam string, currentIndex, pageSize int) (items []*BaseFromLyIndex, err error) {
  61. o := orm.NewOrmUsingDB("data")
  62. sql := `SELECT * FROM base_from_ly_index WHERE 1=1`
  63. var params []interface{}
  64. if searchParam != "" {
  65. sql += ` AND (index_name LIKE ? OR index_code = ?)`
  66. params = append(params, "%"+searchParam+"%", searchParam)
  67. }
  68. sql += ` ORDER BY base_from_ly_index_id DESC LIMIT ?,?`
  69. params = append(params, currentIndex, pageSize)
  70. _, err = o.Raw(sql, params...).QueryRows(&items)
  71. return
  72. }
  73. // UpdateLyIndexEdbExist 指标库标记已添加
  74. func UpdateLyIndexEdbExist(indexCode string) (err error) {
  75. o := orm.NewOrmUsingDB("data")
  76. lyIndex := BaseFromLyIndex{IndexCode: indexCode}
  77. lyIndex.EdbExist = 1
  78. _, err = o.Update(&lyIndex, "edb_exist")
  79. if err != nil {
  80. return err
  81. }
  82. return
  83. }
  84. // GetLyIndexList 根据传入条件查询指标列表
  85. func GetLyIndexList(condition string, pars interface{}) (items []*BaseFromLyIndex, err error) {
  86. o := orm.NewOrmUsingDB("data")
  87. sql := ` SELECT * FROM base_from_ly_index WHERE 1=1 `
  88. if condition != "" {
  89. sql += condition
  90. }
  91. sql += `ORDER BY base_from_ly_index_id ASC `
  92. _, err = o.Raw(sql, pars).QueryRows(&items)
  93. return
  94. }
  95. // GetLyDataMaxCount 获取分类下指标最大数据量
  96. func GetLyDataMaxCount(classifyId int) (count int, err error) {
  97. o := orm.NewOrmUsingDB("data")
  98. sql := `SELECT MAX(t.num) AS count FROM (
  99. SELECT COUNT(1) AS num FROM base_from_ly_index AS a
  100. INNER JOIN base_from_ly_data AS b ON a.base_from_ly_index_id=b.base_from_ly_index_id
  101. WHERE a.base_from_ly_classify_id=?
  102. GROUP BY a.base_from_ly_index_id
  103. )AS t `
  104. err = o.Raw(sql, classifyId).QueryRow(&count)
  105. return
  106. }