list_alarm_conf.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package model
  2. import (
  3. "encoding/json"
  4. "github.com/jaryhe/gopkgs/logger"
  5. "github.com/jinzhu/gorm"
  6. "go.uber.org/zap"
  7. "time"
  8. )
  9. type LiftAlarmConf struct {
  10. ID int64 `gorm:"column:ID;PRIMARY_KEY" `
  11. SN string `gorm:"column:SN"`
  12. ProjectID int64 `gorm:"column:ProjectID" `
  13. MaxWeightAlarm int64 `gorm:"column:MaxWeightAlarm" `
  14. MaxWeightWarning int64 `gorm:"column:MaxWeightWarning" `
  15. MaxHigh float64 `gorm:"column:MaxHigh" `
  16. MaxSpeedAlarm float64 `gorm:"column:MaxSpeedAlarm" `
  17. MaxSpeedWarning float64 `gorm:"column:MaxSpeedWarning" `
  18. MaxPeople int64 `gorm:"column:MaxPeople" `
  19. TiltAlarm float64 `gorm:"column:TiltAlarm" `
  20. TiltWarning float64 `gorm:"column:TiltWarning" `
  21. WindSpeedAlarm float64 `gorm:"column:WindSpeedAlarm" `
  22. WindSpeedWarning float64 `gorm:"column:WindSpeedWarning" `
  23. LiftNo int `gorm:"column:LiftNo"`
  24. LiftDirect int `gorm:"column:LiftDirect"`
  25. CreatedAt time.Time `gorm:"column:CreatedAt"`
  26. UpdatedAt time.Time `gorm:"column:UpdatedAt"`
  27. }
  28. func (LiftAlarmConf) TableName() string {
  29. return "LiftAlarmConf"
  30. }
  31. func (p *LiftAlarmConf) Insert(db *gorm.DB) error {
  32. err := db.Create(p).Error
  33. if err != nil {
  34. fields, _ := json.Marshal(p)
  35. logger.Error("mysql",
  36. zap.String("sql", "insert into LiftAlarmConf"),
  37. zap.String("fields", string(fields)),
  38. zap.String("error", err.Error()))
  39. return err
  40. }
  41. return err
  42. }
  43. func (p *LiftAlarmConf) Find(db *gorm.DB, where map[string]interface{}) error {
  44. cond, val, err := whereBuild(where)
  45. if err != nil {
  46. return err
  47. }
  48. err = db.Table(p.TableName()).Where(cond, val...).First(p).Error
  49. if err != nil {
  50. fields, _ := json.Marshal(where)
  51. logger.Error("mysql",
  52. zap.String("sql", "select from LiftAlarmConf"),
  53. zap.String("fields", string(fields)),
  54. zap.String("error", err.Error()))
  55. return err
  56. }
  57. return err
  58. }
  59. func (p *LiftAlarmConf) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
  60. cond, val, err := whereBuild(where)
  61. if err != nil {
  62. return err
  63. }
  64. err = db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
  65. if err != nil {
  66. fields, _ := json.Marshal(where)
  67. updateValues, _ := json.Marshal(values)
  68. logger.Error("mysql",
  69. zap.String("sql", "update LiftAlarmConf"),
  70. zap.String("fields", string(fields)),
  71. zap.String("values", string(updateValues)),
  72. zap.String("error", err.Error()))
  73. return err
  74. }
  75. return err
  76. }
  77. func (p *LiftAlarmConf) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) {
  78. cond, val, err := whereBuildAndOr(where, or)
  79. if err != nil {
  80. return 0, err
  81. }
  82. ret := int64(0)
  83. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  84. if err != nil {
  85. fields, _ := json.Marshal(val)
  86. logger.Error("mysql",
  87. zap.String("sql", "select count(1) LiftAlarmConf"),
  88. zap.String("fields", cond+","+string(fields)),
  89. zap.String("error", err.Error()))
  90. return ret, err
  91. }
  92. return ret, err
  93. }