package model import ( "encoding/json" "github.com/jaryhe/gopkgs/logger" "github.com/jinzhu/gorm" "go.uber.org/zap" "time" ) type LiftAlarmConf struct { ID int64 `gorm:"column:ID;PRIMARY_KEY" ` SN string `gorm:"column:SN"` ProjectID int64 `gorm:"column:ProjectID" ` MaxWeightAlarm int64 `gorm:"column:MaxWeightAlarm" ` MaxWeightWarning int64 `gorm:"column:MaxWeightWarning" ` MaxHigh float64 `gorm:"column:MaxHigh" ` MaxSpeedAlarm float64 `gorm:"column:MaxSpeedAlarm" ` MaxSpeedWarning float64 `gorm:"column:MaxSpeedWarning" ` MaxPeople int64 `gorm:"column:MaxPeople" ` TiltAlarm float64 `gorm:"column:TiltAlarm" ` TiltWarning float64 `gorm:"column:TiltWarning" ` WindSpeedAlarm float64 `gorm:"column:WindSpeedAlarm" ` WindSpeedWarning float64 `gorm:"column:WindSpeedWarning" ` LiftNo int `gorm:"column:LiftNo"` LiftDirect int `gorm:"column:LiftDirect"` CreatedAt time.Time `gorm:"column:CreatedAt"` UpdatedAt time.Time `gorm:"column:UpdatedAt"` } func (LiftAlarmConf) TableName() string { return "LiftAlarmConf" } func (p *LiftAlarmConf) Insert(db *gorm.DB) error { err := db.Create(p).Error if err != nil { fields, _ := json.Marshal(p) logger.Error("mysql", zap.String("sql", "insert into LiftAlarmConf"), zap.String("fields", string(fields)), zap.String("error", err.Error())) return err } return err } func (p *LiftAlarmConf) Find(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } err = db.Table(p.TableName()).Where(cond, val...).First(p).Error if err != nil { fields, _ := json.Marshal(where) logger.Error("mysql", zap.String("sql", "select from LiftAlarmConf"), zap.String("fields", string(fields)), zap.String("error", err.Error())) return err } return err } func (p *LiftAlarmConf) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } err = db.Table(p.TableName()).Where(cond, val...).Updates(values).Error if err != nil { fields, _ := json.Marshal(where) updateValues, _ := json.Marshal(values) logger.Error("mysql", zap.String("sql", "update LiftAlarmConf"), zap.String("fields", string(fields)), zap.String("values", string(updateValues)), zap.String("error", err.Error())) return err } return err } func (p *LiftAlarmConf) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) { cond, val, err := whereBuildAndOr(where, or) if err != nil { return 0, err } ret := int64(0) err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error if err != nil { fields, _ := json.Marshal(val) logger.Error("mysql", zap.String("sql", "select count(1) LiftAlarmConf"), zap.String("fields", cond+","+string(fields)), zap.String("error", err.Error())) return ret, err } return ret, err }