123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package model
- import (
- "encoding/json"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- "time"
- )
- type LiftSensorConf struct {
- ID int64 `gorm:"column:ID;PRIMARY_KEY" json:"id"`
- SN string `gorm:"column:SN" json:"sn"`
- EmptyWeightAD int64 `gorm:"column:EmptyWeightAD"`
- EmptyWeight int64 `gorm:"column:EmptyWeight"`
- LoadWeightAD int64 `gorm:"column:LoadWeightAD"`
- LoadWeight int64 `gorm:"column:LoadWeight"`
- LowHighAD float64 `gorm:"column:LowHighAD"`
- LowHigh float64 `gorm:"column:LowHigh"`
- TopHighAD float64 `gorm:"column:TopHighAD"`
- TopHigh float64 `gorm:"column:TopHigh"`
- ProjectID int64 `gorm:"column:ProjectID" json:"project_id"`
- LiftNo int `gorm:"column:LiftNo"`
- LiftDirect int `gorm:"column:LiftDirect"`
- CreatedAt time.Time `gorm:"column:CreatedAt"`
- UpdatedAt time.Time `gorm:"column:UpdatedAt"`
- }
- func (LiftSensorConf) TableName() string {
- return "LiftSensorConf"
- }
- func (p *LiftSensorConf) 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 LiftSensorConf"),
- zap.String("fields", string(fields)),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *LiftSensorConf) 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 LiftSensorConf"),
- zap.String("fields", string(fields)),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *LiftSensorConf) 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 LiftSensorConf"),
- zap.String("fields", string(fields)),
- zap.String("values", string(updateValues)),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *LiftSensorConf) 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) LiftSensorConf"),
- zap.String("fields", cond+","+string(fields)),
- zap.String("error", err.Error()))
- return ret, err
- }
- return ret, err
- }
|