123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package model
- import (
- "encoding/json"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- "time"
- )
- type TowerBaseInfo struct {
- ID int64 `gorm:"column:ID;PRIMARY_KEY" json:"id"`
- SN string `gorm:"column:SN" json:"sn"`
- X float64 `gorm:"column:X" json:"x"`
- Y float64 `gorm:"column:Y" json:"y"`
- FrontArmLength float64 `gorm:"column:FrontArmLength" json:"front_arm_length"`
- BackArmLength float64 `gorm:"column:BackArmLength" json:"back_arm_length"`
- HatHigh float64 `gorm:"column:HatHigh" json:"hat_high"`
- ArmHigh float64 `gorm:"column:ArmHigh" json:"arm_high"`
- MaxWeight int64 `gorm:"column:MaxWeight" json:"max_weight"`
- MaxMoment float64 `gorm:"column:MaxMoment" json:"max_moment"`
- HookWeight int64 `gorm:"column:HookWeight" json:"hook_weight"`
- ArticulationLength float64 `gorm:"column:ArticulationLength" json:"articulation_length"`
- HighSensor int64 `gorm:"column:HighSensor" json:"high_sensor"`
- RangeSensor int64 `gorm:"column:RangeSensor" json:"range_sensor"`
- BackturnSensor int64 `gorm:"column:BackturnSensor" json:"backturn_sensor"`
- WeightSensor int64 `gorm:"column:WeightSensor" json:"weight_sensor"`
- WindSensor int64 `gorm:"column:WindSensor" json:"wind_sensor"`
- TiltSendsor int64 `gorm:"column:TiltSendsor" json:"tilt_sendsor"`
- ProjectID int64 `gorm:"column:ProjectID" json:"project_id"`
- TowerNo int `gorm:"column:TowerNo"`
- CreatedAt time.Time `gorm:"column:CreatedAt"`
- UpdatedAt time.Time `gorm:"column:UpdatedAt"`
- }
- func (TowerBaseInfo) TableName() string {
- return "TowerBaseInfo"
- }
- func (p *TowerBaseInfo) 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 TowerBaseInfo"),
- zap.String("fields", string(fields)),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *TowerBaseInfo) 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 TowerBaseInfo"),
- zap.String("fields", string(fields)),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *TowerBaseInfo) 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 TowerBaseInfo"),
- zap.String("fields", string(fields)),
- zap.String("values", string(updateValues)),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *TowerBaseInfo) 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) TowerBaseInfo"),
- zap.String("fields", cond+","+string(fields)),
- zap.String("error", err.Error()))
- return ret, err
- }
- return ret, err
- }
|