package db import ( "applet/app/db/model" "applet/app/utils/logx" "xorm.io/xorm" ) type FactorySetDb struct { Db *xorm.Engine `json:"db"` EnterpriseId int `json:"enterprise_id"` } func (factorySetDb *FactorySetDb) Set(enterpriseId int) { // set方法 factorySetDb.Db = Db factorySetDb.EnterpriseId = enterpriseId } func (factorySetDb *FactorySetDb) GetFactorySet() (m *model.FactorySet, err error) { m = new(model.FactorySet) has, err := factorySetDb.Db.Where("enterprise_id =?", factorySetDb.EnterpriseId).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } func (factorySetDb *FactorySetDb) FactorySetInsert(m *model.FactorySet) (int, error) { _, err := factorySetDb.Db.InsertOne(m) if err != nil { return 0, err } return m.Id, nil } func (factorySetDb *FactorySetDb) FactorySetUpdate(m *model.FactorySet, columns ...string) (int64, error) { affected, err := factorySetDb.Db.Where("enterprise_id =?", factorySetDb.EnterpriseId).Cols(columns...).Update(m) if err != nil { return 0, err } return affected, nil }