From 2bde46a97a9df1bee7161c63d76a4a78aefa8b8d Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 13 Nov 2023 14:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=88=A0=E9=99=A4=E5=8E=9F=E8=BD=AE?= =?UTF-8?q?=E5=BE=84=E4=BF=A1=E6=81=AF=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/dbquery/gen.go | 16 +- db/dbquery/train_sensor.gen.go | 396 ++++++++++++++++++++++++ db/dbquery/train_wheel_diameter.gen.go | 408 ------------------------- db/model/train_sensor.gen.go | 24 ++ db/model/train_wheel_diameter.gen.go | 27 -- service/trainManage.go | 2 +- 6 files changed, 429 insertions(+), 444 deletions(-) create mode 100644 db/dbquery/train_sensor.gen.go delete mode 100644 db/dbquery/train_wheel_diameter.gen.go create mode 100644 db/model/train_sensor.gen.go delete mode 100644 db/model/train_wheel_diameter.gen.go diff --git a/db/dbquery/gen.go b/db/dbquery/gen.go index e41c180..1b81c08 100644 --- a/db/dbquery/gen.go +++ b/db/dbquery/gen.go @@ -29,9 +29,9 @@ var ( ProjectTrainSizeLink *projectTrainSizeLink PublishedGi *publishedGi TrainModel *trainModel + TrainSensor *trainSensor TrainSize *trainSize TrainWheel *trainWheel - TrainWheelDiameter *trainWheelDiameter User *user ) @@ -49,9 +49,9 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) { ProjectTrainSizeLink = &Q.ProjectTrainSizeLink PublishedGi = &Q.PublishedGi TrainModel = &Q.TrainModel + TrainSensor = &Q.TrainSensor TrainSize = &Q.TrainSize TrainWheel = &Q.TrainWheel - TrainWheelDiameter = &Q.TrainWheelDiameter User = &Q.User } @@ -70,9 +70,9 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query { ProjectTrainSizeLink: newProjectTrainSizeLink(db, opts...), PublishedGi: newPublishedGi(db, opts...), TrainModel: newTrainModel(db, opts...), + TrainSensor: newTrainSensor(db, opts...), TrainSize: newTrainSize(db, opts...), TrainWheel: newTrainWheel(db, opts...), - TrainWheelDiameter: newTrainWheelDiameter(db, opts...), User: newUser(db, opts...), } } @@ -92,9 +92,9 @@ type Query struct { ProjectTrainSizeLink projectTrainSizeLink PublishedGi publishedGi TrainModel trainModel + TrainSensor trainSensor TrainSize trainSize TrainWheel trainWheel - TrainWheelDiameter trainWheelDiameter User user } @@ -115,9 +115,9 @@ func (q *Query) clone(db *gorm.DB) *Query { ProjectTrainSizeLink: q.ProjectTrainSizeLink.clone(db), PublishedGi: q.PublishedGi.clone(db), TrainModel: q.TrainModel.clone(db), + TrainSensor: q.TrainSensor.clone(db), TrainSize: q.TrainSize.clone(db), TrainWheel: q.TrainWheel.clone(db), - TrainWheelDiameter: q.TrainWheelDiameter.clone(db), User: q.User.clone(db), } } @@ -145,9 +145,9 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query { ProjectTrainSizeLink: q.ProjectTrainSizeLink.replaceDB(db), PublishedGi: q.PublishedGi.replaceDB(db), TrainModel: q.TrainModel.replaceDB(db), + TrainSensor: q.TrainSensor.replaceDB(db), TrainSize: q.TrainSize.replaceDB(db), TrainWheel: q.TrainWheel.replaceDB(db), - TrainWheelDiameter: q.TrainWheelDiameter.replaceDB(db), User: q.User.replaceDB(db), } } @@ -165,9 +165,9 @@ type queryCtx struct { ProjectTrainSizeLink IProjectTrainSizeLinkDo PublishedGi IPublishedGiDo TrainModel ITrainModelDo + TrainSensor ITrainSensorDo TrainSize ITrainSizeDo TrainWheel ITrainWheelDo - TrainWheelDiameter ITrainWheelDiameterDo User IUserDo } @@ -185,9 +185,9 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx { ProjectTrainSizeLink: q.ProjectTrainSizeLink.WithContext(ctx), PublishedGi: q.PublishedGi.WithContext(ctx), TrainModel: q.TrainModel.WithContext(ctx), + TrainSensor: q.TrainSensor.WithContext(ctx), TrainSize: q.TrainSize.WithContext(ctx), TrainWheel: q.TrainWheel.WithContext(ctx), - TrainWheelDiameter: q.TrainWheelDiameter.WithContext(ctx), User: q.User.WithContext(ctx), } } diff --git a/db/dbquery/train_sensor.gen.go b/db/dbquery/train_sensor.gen.go new file mode 100644 index 0000000..5a905ab --- /dev/null +++ b/db/dbquery/train_sensor.gen.go @@ -0,0 +1,396 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package dbquery + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "joylink.club/bj-rtsts-server/db/model" +) + +func newTrainSensor(db *gorm.DB, opts ...gen.DOOption) trainSensor { + _trainSensor := trainSensor{} + + _trainSensor.trainSensorDo.UseDB(db, opts...) + _trainSensor.trainSensorDo.UseModel(&model.TrainSensor{}) + + tableName := _trainSensor.trainSensorDo.TableName() + _trainSensor.ALL = field.NewAsterisk(tableName) + _trainSensor.ID = field.NewInt32(tableName, "id") + _trainSensor.Name = field.NewString(tableName, "name") + _trainSensor.AxialPosition = field.NewInt32(tableName, "axial_position") + _trainSensor.InstallDirection = field.NewString(tableName, "install_direction") + + _trainSensor.fillFieldMap() + + return _trainSensor +} + +type trainSensor struct { + trainSensorDo + + ALL field.Asterisk + ID field.Int32 + Name field.String // 名称 + AxialPosition field.Int32 // 速度传感器安装轴位,本端车前进方向的第几轴 + /* + 速度传感器安装方向, + 本端车前进方向的左侧或右侧 + */ + InstallDirection field.String + + fieldMap map[string]field.Expr +} + +func (t trainSensor) Table(newTableName string) *trainSensor { + t.trainSensorDo.UseTable(newTableName) + return t.updateTableName(newTableName) +} + +func (t trainSensor) As(alias string) *trainSensor { + t.trainSensorDo.DO = *(t.trainSensorDo.As(alias).(*gen.DO)) + return t.updateTableName(alias) +} + +func (t *trainSensor) updateTableName(table string) *trainSensor { + t.ALL = field.NewAsterisk(table) + t.ID = field.NewInt32(table, "id") + t.Name = field.NewString(table, "name") + t.AxialPosition = field.NewInt32(table, "axial_position") + t.InstallDirection = field.NewString(table, "install_direction") + + t.fillFieldMap() + + return t +} + +func (t *trainSensor) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := t.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (t *trainSensor) fillFieldMap() { + t.fieldMap = make(map[string]field.Expr, 4) + t.fieldMap["id"] = t.ID + t.fieldMap["name"] = t.Name + t.fieldMap["axial_position"] = t.AxialPosition + t.fieldMap["install_direction"] = t.InstallDirection +} + +func (t trainSensor) clone(db *gorm.DB) trainSensor { + t.trainSensorDo.ReplaceConnPool(db.Statement.ConnPool) + return t +} + +func (t trainSensor) replaceDB(db *gorm.DB) trainSensor { + t.trainSensorDo.ReplaceDB(db) + return t +} + +type trainSensorDo struct{ gen.DO } + +type ITrainSensorDo interface { + gen.SubQuery + Debug() ITrainSensorDo + WithContext(ctx context.Context) ITrainSensorDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() ITrainSensorDo + WriteDB() ITrainSensorDo + As(alias string) gen.Dao + Session(config *gorm.Session) ITrainSensorDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) ITrainSensorDo + Not(conds ...gen.Condition) ITrainSensorDo + Or(conds ...gen.Condition) ITrainSensorDo + Select(conds ...field.Expr) ITrainSensorDo + Where(conds ...gen.Condition) ITrainSensorDo + Order(conds ...field.Expr) ITrainSensorDo + Distinct(cols ...field.Expr) ITrainSensorDo + Omit(cols ...field.Expr) ITrainSensorDo + Join(table schema.Tabler, on ...field.Expr) ITrainSensorDo + LeftJoin(table schema.Tabler, on ...field.Expr) ITrainSensorDo + RightJoin(table schema.Tabler, on ...field.Expr) ITrainSensorDo + Group(cols ...field.Expr) ITrainSensorDo + Having(conds ...gen.Condition) ITrainSensorDo + Limit(limit int) ITrainSensorDo + Offset(offset int) ITrainSensorDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) ITrainSensorDo + Unscoped() ITrainSensorDo + Create(values ...*model.TrainSensor) error + CreateInBatches(values []*model.TrainSensor, batchSize int) error + Save(values ...*model.TrainSensor) error + First() (*model.TrainSensor, error) + Take() (*model.TrainSensor, error) + Last() (*model.TrainSensor, error) + Find() ([]*model.TrainSensor, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.TrainSensor, err error) + FindInBatches(result *[]*model.TrainSensor, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.TrainSensor) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) ITrainSensorDo + Assign(attrs ...field.AssignExpr) ITrainSensorDo + Joins(fields ...field.RelationField) ITrainSensorDo + Preload(fields ...field.RelationField) ITrainSensorDo + FirstOrInit() (*model.TrainSensor, error) + FirstOrCreate() (*model.TrainSensor, error) + FindByPage(offset int, limit int) (result []*model.TrainSensor, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) ITrainSensorDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (t trainSensorDo) Debug() ITrainSensorDo { + return t.withDO(t.DO.Debug()) +} + +func (t trainSensorDo) WithContext(ctx context.Context) ITrainSensorDo { + return t.withDO(t.DO.WithContext(ctx)) +} + +func (t trainSensorDo) ReadDB() ITrainSensorDo { + return t.Clauses(dbresolver.Read) +} + +func (t trainSensorDo) WriteDB() ITrainSensorDo { + return t.Clauses(dbresolver.Write) +} + +func (t trainSensorDo) Session(config *gorm.Session) ITrainSensorDo { + return t.withDO(t.DO.Session(config)) +} + +func (t trainSensorDo) Clauses(conds ...clause.Expression) ITrainSensorDo { + return t.withDO(t.DO.Clauses(conds...)) +} + +func (t trainSensorDo) Returning(value interface{}, columns ...string) ITrainSensorDo { + return t.withDO(t.DO.Returning(value, columns...)) +} + +func (t trainSensorDo) Not(conds ...gen.Condition) ITrainSensorDo { + return t.withDO(t.DO.Not(conds...)) +} + +func (t trainSensorDo) Or(conds ...gen.Condition) ITrainSensorDo { + return t.withDO(t.DO.Or(conds...)) +} + +func (t trainSensorDo) Select(conds ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.Select(conds...)) +} + +func (t trainSensorDo) Where(conds ...gen.Condition) ITrainSensorDo { + return t.withDO(t.DO.Where(conds...)) +} + +func (t trainSensorDo) Order(conds ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.Order(conds...)) +} + +func (t trainSensorDo) Distinct(cols ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.Distinct(cols...)) +} + +func (t trainSensorDo) Omit(cols ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.Omit(cols...)) +} + +func (t trainSensorDo) Join(table schema.Tabler, on ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.Join(table, on...)) +} + +func (t trainSensorDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.LeftJoin(table, on...)) +} + +func (t trainSensorDo) RightJoin(table schema.Tabler, on ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.RightJoin(table, on...)) +} + +func (t trainSensorDo) Group(cols ...field.Expr) ITrainSensorDo { + return t.withDO(t.DO.Group(cols...)) +} + +func (t trainSensorDo) Having(conds ...gen.Condition) ITrainSensorDo { + return t.withDO(t.DO.Having(conds...)) +} + +func (t trainSensorDo) Limit(limit int) ITrainSensorDo { + return t.withDO(t.DO.Limit(limit)) +} + +func (t trainSensorDo) Offset(offset int) ITrainSensorDo { + return t.withDO(t.DO.Offset(offset)) +} + +func (t trainSensorDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITrainSensorDo { + return t.withDO(t.DO.Scopes(funcs...)) +} + +func (t trainSensorDo) Unscoped() ITrainSensorDo { + return t.withDO(t.DO.Unscoped()) +} + +func (t trainSensorDo) Create(values ...*model.TrainSensor) error { + if len(values) == 0 { + return nil + } + return t.DO.Create(values) +} + +func (t trainSensorDo) CreateInBatches(values []*model.TrainSensor, batchSize int) error { + return t.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (t trainSensorDo) Save(values ...*model.TrainSensor) error { + if len(values) == 0 { + return nil + } + return t.DO.Save(values) +} + +func (t trainSensorDo) First() (*model.TrainSensor, error) { + if result, err := t.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.TrainSensor), nil + } +} + +func (t trainSensorDo) Take() (*model.TrainSensor, error) { + if result, err := t.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.TrainSensor), nil + } +} + +func (t trainSensorDo) Last() (*model.TrainSensor, error) { + if result, err := t.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.TrainSensor), nil + } +} + +func (t trainSensorDo) Find() ([]*model.TrainSensor, error) { + result, err := t.DO.Find() + return result.([]*model.TrainSensor), err +} + +func (t trainSensorDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.TrainSensor, err error) { + buf := make([]*model.TrainSensor, 0, batchSize) + err = t.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (t trainSensorDo) FindInBatches(result *[]*model.TrainSensor, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return t.DO.FindInBatches(result, batchSize, fc) +} + +func (t trainSensorDo) Attrs(attrs ...field.AssignExpr) ITrainSensorDo { + return t.withDO(t.DO.Attrs(attrs...)) +} + +func (t trainSensorDo) Assign(attrs ...field.AssignExpr) ITrainSensorDo { + return t.withDO(t.DO.Assign(attrs...)) +} + +func (t trainSensorDo) Joins(fields ...field.RelationField) ITrainSensorDo { + for _, _f := range fields { + t = *t.withDO(t.DO.Joins(_f)) + } + return &t +} + +func (t trainSensorDo) Preload(fields ...field.RelationField) ITrainSensorDo { + for _, _f := range fields { + t = *t.withDO(t.DO.Preload(_f)) + } + return &t +} + +func (t trainSensorDo) FirstOrInit() (*model.TrainSensor, error) { + if result, err := t.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.TrainSensor), nil + } +} + +func (t trainSensorDo) FirstOrCreate() (*model.TrainSensor, error) { + if result, err := t.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.TrainSensor), nil + } +} + +func (t trainSensorDo) FindByPage(offset int, limit int) (result []*model.TrainSensor, count int64, err error) { + result, err = t.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = t.Offset(-1).Limit(-1).Count() + return +} + +func (t trainSensorDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = t.Count() + if err != nil { + return + } + + err = t.Offset(offset).Limit(limit).Scan(result) + return +} + +func (t trainSensorDo) Scan(result interface{}) (err error) { + return t.DO.Scan(result) +} + +func (t trainSensorDo) Delete(models ...*model.TrainSensor) (result gen.ResultInfo, err error) { + return t.DO.Delete(models) +} + +func (t *trainSensorDo) withDO(do gen.Dao) *trainSensorDo { + t.DO = *do.(*gen.DO) + return t +} diff --git a/db/dbquery/train_wheel_diameter.gen.go b/db/dbquery/train_wheel_diameter.gen.go deleted file mode 100644 index 6b512d4..0000000 --- a/db/dbquery/train_wheel_diameter.gen.go +++ /dev/null @@ -1,408 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package dbquery - -import ( - "context" - - "gorm.io/gorm" - "gorm.io/gorm/clause" - "gorm.io/gorm/schema" - - "gorm.io/gen" - "gorm.io/gen/field" - - "gorm.io/plugin/dbresolver" - - "joylink.club/bj-rtsts-server/db/model" -) - -func newTrainWheelDiameter(db *gorm.DB, opts ...gen.DOOption) trainWheelDiameter { - _trainWheelDiameter := trainWheelDiameter{} - - _trainWheelDiameter.trainWheelDiameterDo.UseDB(db, opts...) - _trainWheelDiameter.trainWheelDiameterDo.UseModel(&model.TrainWheelDiameter{}) - - tableName := _trainWheelDiameter.trainWheelDiameterDo.TableName() - _trainWheelDiameter.ALL = field.NewAsterisk(tableName) - _trainWheelDiameter.ID = field.NewInt32(tableName, "id") - _trainWheelDiameter.Name = field.NewString(tableName, "name") - _trainWheelDiameter.Diameter = field.NewInt32(tableName, "diameter") - _trainWheelDiameter.MinDiameter = field.NewInt32(tableName, "min_diameter") - _trainWheelDiameter.MaxDiameter = field.NewInt32(tableName, "max_diameter") - _trainWheelDiameter.AxialPosition = field.NewInt32(tableName, "axial_position") - _trainWheelDiameter.InstallDirection = field.NewString(tableName, "install_direction") - - _trainWheelDiameter.fillFieldMap() - - return _trainWheelDiameter -} - -type trainWheelDiameter struct { - trainWheelDiameterDo - - ALL field.Asterisk - ID field.Int32 - Name field.String // 名称 - Diameter field.Int32 // 速度传感器安装处车轮的出厂直径(mm) - MinDiameter field.Int32 // 速度传感器安装处车轮的最小直径(mm) - MaxDiameter field.Int32 // 速度传感器安装处车轮的最大直径(mm) - AxialPosition field.Int32 // 速度传感器安装轴位,本端车前进方向的第几轴 - /* - 速度传感器安装方向, - 本端车前进方向的左侧或右侧 - */ - InstallDirection field.String - - fieldMap map[string]field.Expr -} - -func (t trainWheelDiameter) Table(newTableName string) *trainWheelDiameter { - t.trainWheelDiameterDo.UseTable(newTableName) - return t.updateTableName(newTableName) -} - -func (t trainWheelDiameter) As(alias string) *trainWheelDiameter { - t.trainWheelDiameterDo.DO = *(t.trainWheelDiameterDo.As(alias).(*gen.DO)) - return t.updateTableName(alias) -} - -func (t *trainWheelDiameter) updateTableName(table string) *trainWheelDiameter { - t.ALL = field.NewAsterisk(table) - t.ID = field.NewInt32(table, "id") - t.Name = field.NewString(table, "name") - t.Diameter = field.NewInt32(table, "diameter") - t.MinDiameter = field.NewInt32(table, "min_diameter") - t.MaxDiameter = field.NewInt32(table, "max_diameter") - t.AxialPosition = field.NewInt32(table, "axial_position") - t.InstallDirection = field.NewString(table, "install_direction") - - t.fillFieldMap() - - return t -} - -func (t *trainWheelDiameter) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := t.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (t *trainWheelDiameter) fillFieldMap() { - t.fieldMap = make(map[string]field.Expr, 7) - t.fieldMap["id"] = t.ID - t.fieldMap["name"] = t.Name - t.fieldMap["diameter"] = t.Diameter - t.fieldMap["min_diameter"] = t.MinDiameter - t.fieldMap["max_diameter"] = t.MaxDiameter - t.fieldMap["axial_position"] = t.AxialPosition - t.fieldMap["install_direction"] = t.InstallDirection -} - -func (t trainWheelDiameter) clone(db *gorm.DB) trainWheelDiameter { - t.trainWheelDiameterDo.ReplaceConnPool(db.Statement.ConnPool) - return t -} - -func (t trainWheelDiameter) replaceDB(db *gorm.DB) trainWheelDiameter { - t.trainWheelDiameterDo.ReplaceDB(db) - return t -} - -type trainWheelDiameterDo struct{ gen.DO } - -type ITrainWheelDiameterDo interface { - gen.SubQuery - Debug() ITrainWheelDiameterDo - WithContext(ctx context.Context) ITrainWheelDiameterDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() ITrainWheelDiameterDo - WriteDB() ITrainWheelDiameterDo - As(alias string) gen.Dao - Session(config *gorm.Session) ITrainWheelDiameterDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) ITrainWheelDiameterDo - Not(conds ...gen.Condition) ITrainWheelDiameterDo - Or(conds ...gen.Condition) ITrainWheelDiameterDo - Select(conds ...field.Expr) ITrainWheelDiameterDo - Where(conds ...gen.Condition) ITrainWheelDiameterDo - Order(conds ...field.Expr) ITrainWheelDiameterDo - Distinct(cols ...field.Expr) ITrainWheelDiameterDo - Omit(cols ...field.Expr) ITrainWheelDiameterDo - Join(table schema.Tabler, on ...field.Expr) ITrainWheelDiameterDo - LeftJoin(table schema.Tabler, on ...field.Expr) ITrainWheelDiameterDo - RightJoin(table schema.Tabler, on ...field.Expr) ITrainWheelDiameterDo - Group(cols ...field.Expr) ITrainWheelDiameterDo - Having(conds ...gen.Condition) ITrainWheelDiameterDo - Limit(limit int) ITrainWheelDiameterDo - Offset(offset int) ITrainWheelDiameterDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) ITrainWheelDiameterDo - Unscoped() ITrainWheelDiameterDo - Create(values ...*model.TrainWheelDiameter) error - CreateInBatches(values []*model.TrainWheelDiameter, batchSize int) error - Save(values ...*model.TrainWheelDiameter) error - First() (*model.TrainWheelDiameter, error) - Take() (*model.TrainWheelDiameter, error) - Last() (*model.TrainWheelDiameter, error) - Find() ([]*model.TrainWheelDiameter, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.TrainWheelDiameter, err error) - FindInBatches(result *[]*model.TrainWheelDiameter, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*model.TrainWheelDiameter) (info gen.ResultInfo, err error) - Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - Updates(value interface{}) (info gen.ResultInfo, err error) - UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) - UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) - UpdateColumns(value interface{}) (info gen.ResultInfo, err error) - UpdateFrom(q gen.SubQuery) gen.Dao - Attrs(attrs ...field.AssignExpr) ITrainWheelDiameterDo - Assign(attrs ...field.AssignExpr) ITrainWheelDiameterDo - Joins(fields ...field.RelationField) ITrainWheelDiameterDo - Preload(fields ...field.RelationField) ITrainWheelDiameterDo - FirstOrInit() (*model.TrainWheelDiameter, error) - FirstOrCreate() (*model.TrainWheelDiameter, error) - FindByPage(offset int, limit int) (result []*model.TrainWheelDiameter, count int64, err error) - ScanByPage(result interface{}, offset int, limit int) (count int64, err error) - Scan(result interface{}) (err error) - Returning(value interface{}, columns ...string) ITrainWheelDiameterDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (t trainWheelDiameterDo) Debug() ITrainWheelDiameterDo { - return t.withDO(t.DO.Debug()) -} - -func (t trainWheelDiameterDo) WithContext(ctx context.Context) ITrainWheelDiameterDo { - return t.withDO(t.DO.WithContext(ctx)) -} - -func (t trainWheelDiameterDo) ReadDB() ITrainWheelDiameterDo { - return t.Clauses(dbresolver.Read) -} - -func (t trainWheelDiameterDo) WriteDB() ITrainWheelDiameterDo { - return t.Clauses(dbresolver.Write) -} - -func (t trainWheelDiameterDo) Session(config *gorm.Session) ITrainWheelDiameterDo { - return t.withDO(t.DO.Session(config)) -} - -func (t trainWheelDiameterDo) Clauses(conds ...clause.Expression) ITrainWheelDiameterDo { - return t.withDO(t.DO.Clauses(conds...)) -} - -func (t trainWheelDiameterDo) Returning(value interface{}, columns ...string) ITrainWheelDiameterDo { - return t.withDO(t.DO.Returning(value, columns...)) -} - -func (t trainWheelDiameterDo) Not(conds ...gen.Condition) ITrainWheelDiameterDo { - return t.withDO(t.DO.Not(conds...)) -} - -func (t trainWheelDiameterDo) Or(conds ...gen.Condition) ITrainWheelDiameterDo { - return t.withDO(t.DO.Or(conds...)) -} - -func (t trainWheelDiameterDo) Select(conds ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Select(conds...)) -} - -func (t trainWheelDiameterDo) Where(conds ...gen.Condition) ITrainWheelDiameterDo { - return t.withDO(t.DO.Where(conds...)) -} - -func (t trainWheelDiameterDo) Order(conds ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Order(conds...)) -} - -func (t trainWheelDiameterDo) Distinct(cols ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Distinct(cols...)) -} - -func (t trainWheelDiameterDo) Omit(cols ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Omit(cols...)) -} - -func (t trainWheelDiameterDo) Join(table schema.Tabler, on ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Join(table, on...)) -} - -func (t trainWheelDiameterDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.LeftJoin(table, on...)) -} - -func (t trainWheelDiameterDo) RightJoin(table schema.Tabler, on ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.RightJoin(table, on...)) -} - -func (t trainWheelDiameterDo) Group(cols ...field.Expr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Group(cols...)) -} - -func (t trainWheelDiameterDo) Having(conds ...gen.Condition) ITrainWheelDiameterDo { - return t.withDO(t.DO.Having(conds...)) -} - -func (t trainWheelDiameterDo) Limit(limit int) ITrainWheelDiameterDo { - return t.withDO(t.DO.Limit(limit)) -} - -func (t trainWheelDiameterDo) Offset(offset int) ITrainWheelDiameterDo { - return t.withDO(t.DO.Offset(offset)) -} - -func (t trainWheelDiameterDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITrainWheelDiameterDo { - return t.withDO(t.DO.Scopes(funcs...)) -} - -func (t trainWheelDiameterDo) Unscoped() ITrainWheelDiameterDo { - return t.withDO(t.DO.Unscoped()) -} - -func (t trainWheelDiameterDo) Create(values ...*model.TrainWheelDiameter) error { - if len(values) == 0 { - return nil - } - return t.DO.Create(values) -} - -func (t trainWheelDiameterDo) CreateInBatches(values []*model.TrainWheelDiameter, batchSize int) error { - return t.DO.CreateInBatches(values, batchSize) -} - -// Save : !!! underlying implementation is different with GORM -// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) -func (t trainWheelDiameterDo) Save(values ...*model.TrainWheelDiameter) error { - if len(values) == 0 { - return nil - } - return t.DO.Save(values) -} - -func (t trainWheelDiameterDo) First() (*model.TrainWheelDiameter, error) { - if result, err := t.DO.First(); err != nil { - return nil, err - } else { - return result.(*model.TrainWheelDiameter), nil - } -} - -func (t trainWheelDiameterDo) Take() (*model.TrainWheelDiameter, error) { - if result, err := t.DO.Take(); err != nil { - return nil, err - } else { - return result.(*model.TrainWheelDiameter), nil - } -} - -func (t trainWheelDiameterDo) Last() (*model.TrainWheelDiameter, error) { - if result, err := t.DO.Last(); err != nil { - return nil, err - } else { - return result.(*model.TrainWheelDiameter), nil - } -} - -func (t trainWheelDiameterDo) Find() ([]*model.TrainWheelDiameter, error) { - result, err := t.DO.Find() - return result.([]*model.TrainWheelDiameter), err -} - -func (t trainWheelDiameterDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.TrainWheelDiameter, err error) { - buf := make([]*model.TrainWheelDiameter, 0, batchSize) - err = t.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { - defer func() { results = append(results, buf...) }() - return fc(tx, batch) - }) - return results, err -} - -func (t trainWheelDiameterDo) FindInBatches(result *[]*model.TrainWheelDiameter, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return t.DO.FindInBatches(result, batchSize, fc) -} - -func (t trainWheelDiameterDo) Attrs(attrs ...field.AssignExpr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Attrs(attrs...)) -} - -func (t trainWheelDiameterDo) Assign(attrs ...field.AssignExpr) ITrainWheelDiameterDo { - return t.withDO(t.DO.Assign(attrs...)) -} - -func (t trainWheelDiameterDo) Joins(fields ...field.RelationField) ITrainWheelDiameterDo { - for _, _f := range fields { - t = *t.withDO(t.DO.Joins(_f)) - } - return &t -} - -func (t trainWheelDiameterDo) Preload(fields ...field.RelationField) ITrainWheelDiameterDo { - for _, _f := range fields { - t = *t.withDO(t.DO.Preload(_f)) - } - return &t -} - -func (t trainWheelDiameterDo) FirstOrInit() (*model.TrainWheelDiameter, error) { - if result, err := t.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*model.TrainWheelDiameter), nil - } -} - -func (t trainWheelDiameterDo) FirstOrCreate() (*model.TrainWheelDiameter, error) { - if result, err := t.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*model.TrainWheelDiameter), nil - } -} - -func (t trainWheelDiameterDo) FindByPage(offset int, limit int) (result []*model.TrainWheelDiameter, count int64, err error) { - result, err = t.Offset(offset).Limit(limit).Find() - if err != nil { - return - } - - if size := len(result); 0 < limit && 0 < size && size < limit { - count = int64(size + offset) - return - } - - count, err = t.Offset(-1).Limit(-1).Count() - return -} - -func (t trainWheelDiameterDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = t.Count() - if err != nil { - return - } - - err = t.Offset(offset).Limit(limit).Scan(result) - return -} - -func (t trainWheelDiameterDo) Scan(result interface{}) (err error) { - return t.DO.Scan(result) -} - -func (t trainWheelDiameterDo) Delete(models ...*model.TrainWheelDiameter) (result gen.ResultInfo, err error) { - return t.DO.Delete(models) -} - -func (t *trainWheelDiameterDo) withDO(do gen.Dao) *trainWheelDiameterDo { - t.DO = *do.(*gen.DO) - return t -} diff --git a/db/model/train_sensor.gen.go b/db/model/train_sensor.gen.go new file mode 100644 index 0000000..87da0fc --- /dev/null +++ b/db/model/train_sensor.gen.go @@ -0,0 +1,24 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +const TableNameTrainSensor = "train_sensor" + +// TrainSensor mapped from table +type TrainSensor struct { + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` + Name string `gorm:"column:name;comment:名称" json:"name"` // 名称 + AxialPosition int32 `gorm:"column:axial_position;comment:速度传感器安装轴位,本端车前进方向的第几轴" json:"axial_position"` // 速度传感器安装轴位,本端车前进方向的第几轴 + /* + 速度传感器安装方向, + 本端车前进方向的左侧或右侧 + */ + InstallDirection string `gorm:"column:install_direction;comment:速度传感器安装方向,\n本端车前进方向的左侧或右侧" json:"install_direction"` +} + +// TableName TrainSensor's table name +func (*TrainSensor) TableName() string { + return TableNameTrainSensor +} diff --git a/db/model/train_wheel_diameter.gen.go b/db/model/train_wheel_diameter.gen.go deleted file mode 100644 index 8adcf56..0000000 --- a/db/model/train_wheel_diameter.gen.go +++ /dev/null @@ -1,27 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package model - -const TableNameTrainWheelDiameter = "train_wheel_diameter" - -// TrainWheelDiameter mapped from table -type TrainWheelDiameter struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` - Name string `gorm:"column:name;comment:名称" json:"name"` // 名称 - Diameter int32 `gorm:"column:diameter;comment:速度传感器安装处车轮的出厂直径(mm)" json:"diameter"` // 速度传感器安装处车轮的出厂直径(mm) - MinDiameter int32 `gorm:"column:min_diameter;comment:速度传感器安装处车轮的最小直径(mm)" json:"min_diameter"` // 速度传感器安装处车轮的最小直径(mm) - MaxDiameter int32 `gorm:"column:max_diameter;comment:速度传感器安装处车轮的最大直径(mm)" json:"max_diameter"` // 速度传感器安装处车轮的最大直径(mm) - AxialPosition int32 `gorm:"column:axial_position;comment:速度传感器安装轴位,本端车前进方向的第几轴" json:"axial_position"` // 速度传感器安装轴位,本端车前进方向的第几轴 - /* - 速度传感器安装方向, - 本端车前进方向的左侧或右侧 - */ - InstallDirection string `gorm:"column:install_direction;comment:速度传感器安装方向,\n本端车前进方向的左侧或右侧" json:"install_direction"` -} - -// TableName TrainWheelDiameter's table name -func (*TrainWheelDiameter) TableName() string { - return TableNameTrainWheelDiameter -} diff --git a/service/trainManage.go b/service/trainManage.go index 7c0ab6c..c36e46e 100644 --- a/service/trainManage.go +++ b/service/trainManage.go @@ -259,7 +259,7 @@ func UpdateTrainWheelDiameter(id int32, twd *dto.TrainWheelDto) bool { oldD.Name = twd.Name oldD.MinDiameter = twd.MinDiameter oldD.MaxDiameter = twd.MaxDiameter - _, err2 := dbquery.TrainWheelDiameter.Updates(oldD) + _, err2 := dbquery.TrainWheel.Updates(oldD) if err2 != nil { panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err2.Error()}) }