智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. type FactorySetDb struct {
  8. Db *xorm.Engine `json:"db"`
  9. EnterpriseId int `json:"enterprise_id"`
  10. }
  11. func (factorySetDb *FactorySetDb) Set(enterpriseId int) { // set方法
  12. factorySetDb.Db = Db
  13. factorySetDb.EnterpriseId = enterpriseId
  14. }
  15. func (factorySetDb *FactorySetDb) GetFactorySet() (m *model.FactorySet, err error) {
  16. m = new(model.FactorySet)
  17. has, err := factorySetDb.Db.Where("enterprise_id =?", factorySetDb.EnterpriseId).Get(m)
  18. if err != nil {
  19. return nil, logx.Error(err)
  20. }
  21. if has == false {
  22. return nil, nil
  23. }
  24. return m, nil
  25. }
  26. func (factorySetDb *FactorySetDb) FactorySetInsert(m *model.FactorySet) (int, error) {
  27. _, err := factorySetDb.Db.InsertOne(m)
  28. if err != nil {
  29. return 0, err
  30. }
  31. return m.Id, nil
  32. }
  33. func (factorySetDb *FactorySetDb) FactorySetUpdate(m *model.FactorySet, columns ...string) (int64, error) {
  34. affected, err := factorySetDb.Db.Where("enterprise_id =?", factorySetDb.EnterpriseId).Cols(columns...).Update(m)
  35. if err != nil {
  36. return 0, err
  37. }
  38. return affected, nil
  39. }