123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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
- }
|