package db import ( "applet/app/db/model" "applet/app/utils/logx" "reflect" "xorm.io/xorm" ) type FactoryOrd struct { Db *xorm.Engine `json:"db"` OutOrderNo string `json:"user_identity_id"` } func (factoryOrdOrdDb *FactoryOrd) Set(outOrderNo string) { // set方法 factoryOrdOrdDb.Db = Db factoryOrdOrdDb.OutOrderNo = outOrderNo } func (factoryOrdOrdDb *FactoryOrd) GetFactoryOrdById(id int) (m *model.FactoryOrd, err error) { m = new(model.FactoryOrd) has, err := factoryOrdOrdDb.Db.Where("id =?", id).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } func (factoryOrdOrdDb *FactoryOrd) GetFactoryOrd() (m *model.FactoryOrd, err error) { m = new(model.FactoryOrd) has, err := factoryOrdOrdDb.Db.Where("out_order_no =?", factoryOrdOrdDb.OutOrderNo).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } func (factoryOrdOrdDb *FactoryOrd) FactoryOrdInsert(m *model.FactoryOrd) (int, error) { _, err := factoryOrdOrdDb.Db.InsertOne(m) if err != nil { return 0, err } return m.Id, nil } func (factoryOrdOrdDb *FactoryOrd) FactoryOrdInsertBySession(session *xorm.Session, m *model.FactoryOrd) (int, error) { _, err := session.InsertOne(m) if err != nil { return 0, err } return m.Id, nil } func (factoryOrdOrdDb *FactoryOrd) BatchAddFactoryOrds(mm []*model.FactoryOrd) (int64, error) { affected, err := factoryOrdOrdDb.Db.Insert(mm) if err != nil { return 0, err } return affected, nil } func (factoryOrdOrdDb *FactoryOrd) FactoryOrdDeleteById(id interface{}) (int64, error) { if reflect.TypeOf(id).Kind() == reflect.Slice { return Db.In("id", id).Delete(model.FactoryOrd{}) } else { return Db.Where("id = ?", id).Delete(model.FactoryOrd{}) } } func (factoryOrdOrdDb *FactoryOrd) FactoryOrdDelete() (int64, error) { return Db.Where("out_order_no = ?", factoryOrdOrdDb.OutOrderNo).Delete(model.FactoryOrd{}) } func (factoryOrdOrdDb *FactoryOrd) FactoryOrdUpdate(m *model.FactoryOrd, forceColums ...string) (int64, error) { var ( affected int64 err error ) if forceColums != nil { affected, err = factoryOrdOrdDb.Db.Where("out_order_no=?", factoryOrdOrdDb.OutOrderNo).Cols(forceColums...).Update(m) } else { affected, err = factoryOrdOrdDb.Db.Where("out_order_no=?", factoryOrdOrdDb.OutOrderNo).Update(m) } if err != nil { return 0, err } return affected, nil } type FactoryOrdWithUserIdentity struct { model.FactoryOrd `xorm:"extends"` model.UserIdentity `xorm:"extends"` model.Enterprise `xorm:"extends"` model.User `xorm:"extends"` model.FactoryDevice `xorm:"extends"` } func (FactoryOrdWithUserIdentity) TableName() string { return "factory_ord" } type FactoryOrdWithUserIdentityV2 struct { model.FactoryOrd `xorm:"extends"` model.Enterprise `xorm:"extends"` } func (FactoryOrdWithUserIdentityV2) TableName() string { return "factory_ord" }