edb_data_calculate_stl.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type EdbDataCalculateStl struct {
  7. EdbDataId int `orm:"pk"`
  8. EdbInfoId int `description:"指标id"`
  9. EdbCode string `description:"指标编码"`
  10. DataTime time.Time `description:"数据时间"`
  11. Value float64 `description:"数据值"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. DataTimestamp int64 `description:"数据时间戳"`
  15. }
  16. type CalculateStlConfigMapping struct {
  17. Id int `orm:"pk" description:"主键"`
  18. CalculateStlConfigId int `description:"stl配置id"`
  19. EdbInfoId int `description:"edb信息id"`
  20. StlEdbType int `description:"stl指标类型: 1-Trend, 2-Seasonal, 3-Residual"`
  21. CreateTime time.Time `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. }
  24. type CalculateStlConfig struct {
  25. CalculateStlConfigId int `orm:"column(calculate_stl_config_id);pk"`
  26. Config string `description:"STL计算配置"`
  27. SysUserId int `description:"系统用户ID"`
  28. CreateTime time.Time `description:"创建时间"`
  29. ModifyTime time.Time `description:"更新时间"`
  30. }
  31. func GetRelationCalculateStlConfigMappingByEdbInfoId(edbInfoId int) (items []*CalculateStlConfigMapping, err error) {
  32. o := orm.NewOrm()
  33. sql := `SELECT calculate_stl_config_id FROM calculate_stl_config_mapping WHERE edb_info_id =? LIMIT 1`
  34. var confId int
  35. err = o.Raw(sql, edbInfoId).QueryRow(&confId)
  36. if err != nil {
  37. return
  38. }
  39. sql = `SELECT * FROM calculate_stl_config_mapping WHERE calculate_stl_config_id =?`
  40. _, err = o.Raw(sql, confId).QueryRows(&items)
  41. return
  42. }
  43. // GetCalculateStlConfigMappingByConfigId 根据配置文件id获取配置文件映射信息
  44. func GetCalculateStlConfigMappingByConfigId(configId int) (items []*CalculateStlConfigMapping, err error) {
  45. o := orm.NewOrm()
  46. sql := `SELECT * FROM calculate_stl_config_mapping WHERE calculate_stl_config_id=?`
  47. _, err = o.Raw(sql, configId).QueryRows(&items)
  48. return
  49. }
  50. // GetCalculateStlConfigMappingIdByEdbInfoId 获取配置文件id
  51. func GetCalculateStlConfigMappingIdByEdbInfoId(edbInfoId int) (configId int, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT calculate_stl_config_id FROM calculate_stl_config_mapping WHERE edb_info_id=? LIMIT 1`
  54. err = o.Raw(sql, edbInfoId).QueryRow(&configId)
  55. return
  56. }
  57. func DeleteAndInsertEdbDataCalculateStl(edbCode string, dataList []*EdbDataCalculateStl) (err error) {
  58. tx, err := orm.NewOrm().Begin()
  59. if err != nil {
  60. return
  61. }
  62. defer func() {
  63. if err != nil {
  64. tx.Rollback()
  65. } else {
  66. tx.Commit()
  67. }
  68. }()
  69. sql := `DELETE FROM edb_data_calculate_stl WHERE edb_code =?`
  70. _, err = tx.Raw(sql, edbCode).Exec()
  71. if err != nil {
  72. return
  73. }
  74. _, err = tx.InsertMulti(500, dataList)
  75. return
  76. }
  77. func (c *CalculateStlConfig) Update(cols []string) (err error) {
  78. o := orm.NewOrm()
  79. _, err = o.Update(c, cols...)
  80. return
  81. }
  82. func GetCalculateStlConfigById(id int) (item *CalculateStlConfig, err error) {
  83. o := orm.NewOrm()
  84. sql := "SELECT * FROM calculate_stl_config WHERE calculate_stl_config_id =?"
  85. err = o.Raw(sql, id).QueryRow(&item)
  86. return
  87. }