base_from_ly_index.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // 创建查询条件
  43. qs := o.QueryTable("base_from_ly_index")
  44. // 使用 Filter 进行查询
  45. _, err = qs.Filter("base_from_ly_classify_id__in", classifyIds).All(&items)
  46. return
  47. }
  48. // GetLyIndexCount 获取指标总数
  49. func GetLyIndexCount(searchParam string) (count int, err error) {
  50. o := orm.NewOrmUsingDB("data")
  51. sql := `SELECT count(*) FROM base_from_ly_index WHERE 1=1`
  52. var params []interface{}
  53. if searchParam != "" {
  54. sql += ` AND (index_name LIKE ? OR index_code = ?)`
  55. params = append(params, "%"+searchParam+"%", searchParam)
  56. }
  57. sql += ` ORDER BY base_from_ly_index_id DESC`
  58. err = o.Raw(sql, params...).QueryRow(&count)
  59. return
  60. }
  61. // GetLyIndexPage 获取指标列表
  62. func GetLyIndexPage(searchParam string, currentIndex, pageSize int) (items []*BaseFromLyIndex, err error) {
  63. o := orm.NewOrmUsingDB("data")
  64. sql := `SELECT * FROM base_from_ly_index WHERE 1=1`
  65. var params []interface{}
  66. if searchParam != "" {
  67. sql += ` AND (index_name LIKE ? OR index_code = ?)`
  68. params = append(params, "%"+searchParam+"%", searchParam)
  69. }
  70. sql += ` ORDER BY base_from_ly_index_id DESC LIMIT ?,?`
  71. params = append(params, currentIndex, pageSize)
  72. _, err = o.Raw(sql, params...).QueryRows(&items)
  73. return
  74. }
  75. // UpdateLyIndexEdbExist 指标库标记已添加
  76. func UpdateLyIndexEdbExist(indexCode string) (err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. lyIndex := BaseFromLyIndex{IndexCode: indexCode}
  79. lyIndex.EdbExist = 1
  80. _, err = o.Update(&lyIndex, "edb_exist")
  81. if err != nil {
  82. return err
  83. }
  84. return
  85. }
  86. // GetLyIndexList 根据传入条件查询指标列表
  87. func GetLyIndexList(condition string, pars interface{}) (items []*BaseFromLyIndex, err error) {
  88. o := orm.NewOrmUsingDB("data")
  89. sql := ` SELECT * FROM base_from_ly_index WHERE 1=1 `
  90. if condition != "" {
  91. sql += condition
  92. }
  93. sql += `ORDER BY base_from_ly_index_id ASC `
  94. _, err = o.Raw(sql, pars).QueryRows(&items)
  95. return
  96. }
  97. // GetLyDataMaxCount 获取分类下指标最大数据量
  98. func GetLyDataMaxCount(classifyId int) (count int, err error) {
  99. o := orm.NewOrmUsingDB("data")
  100. sql := `SELECT MAX(t.num) AS count FROM (
  101. SELECT COUNT(1) AS num FROM base_from_ly_index AS a
  102. INNER JOIN base_from_ly_data AS b ON a.base_from_ly_index_id=b.base_from_ly_index_id
  103. WHERE a.base_from_ly_classify_id=?
  104. GROUP BY a.base_from_ly_index_id
  105. )AS t `
  106. err = o.Raw(sql, classifyId).QueryRow(&count)
  107. return
  108. }