智慧食堂
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.

db_factory_ord.go 2.9 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type FactoryOrd struct {
  9. Db *xorm.Engine `json:"db"`
  10. OutOrderNo string `json:"user_identity_id"`
  11. }
  12. func (factoryOrdOrdDb *FactoryOrd) Set(outOrderNo string) { // set方法
  13. factoryOrdOrdDb.Db = Db
  14. factoryOrdOrdDb.OutOrderNo = outOrderNo
  15. }
  16. func (factoryOrdOrdDb *FactoryOrd) GetFactoryOrdById(id int) (m *model.FactoryOrd, err error) {
  17. m = new(model.FactoryOrd)
  18. has, err := factoryOrdOrdDb.Db.Where("id =?", id).Get(m)
  19. if err != nil {
  20. return nil, logx.Error(err)
  21. }
  22. if has == false {
  23. return nil, nil
  24. }
  25. return m, nil
  26. }
  27. func (factoryOrdOrdDb *FactoryOrd) GetFactoryOrd() (m *model.FactoryOrd, err error) {
  28. m = new(model.FactoryOrd)
  29. has, err := factoryOrdOrdDb.Db.Where("out_order_no =?", factoryOrdOrdDb.OutOrderNo).Get(m)
  30. if err != nil {
  31. return nil, logx.Error(err)
  32. }
  33. if has == false {
  34. return nil, nil
  35. }
  36. return m, nil
  37. }
  38. func (factoryOrdOrdDb *FactoryOrd) FactoryOrdInsert(m *model.FactoryOrd) (int, error) {
  39. _, err := factoryOrdOrdDb.Db.InsertOne(m)
  40. if err != nil {
  41. return 0, err
  42. }
  43. return m.Id, nil
  44. }
  45. func (factoryOrdOrdDb *FactoryOrd) FactoryOrdInsertBySession(session *xorm.Session, m *model.FactoryOrd) (int, error) {
  46. _, err := session.InsertOne(m)
  47. if err != nil {
  48. return 0, err
  49. }
  50. return m.Id, nil
  51. }
  52. func (factoryOrdOrdDb *FactoryOrd) BatchAddFactoryOrds(mm []*model.FactoryOrd) (int64, error) {
  53. affected, err := factoryOrdOrdDb.Db.Insert(mm)
  54. if err != nil {
  55. return 0, err
  56. }
  57. return affected, nil
  58. }
  59. func (factoryOrdOrdDb *FactoryOrd) FactoryOrdDeleteById(id interface{}) (int64, error) {
  60. if reflect.TypeOf(id).Kind() == reflect.Slice {
  61. return Db.In("id", id).Delete(model.FactoryOrd{})
  62. } else {
  63. return Db.Where("id = ?", id).Delete(model.FactoryOrd{})
  64. }
  65. }
  66. func (factoryOrdOrdDb *FactoryOrd) FactoryOrdDelete() (int64, error) {
  67. return Db.Where("out_order_no = ?", factoryOrdOrdDb.OutOrderNo).Delete(model.FactoryOrd{})
  68. }
  69. func (factoryOrdOrdDb *FactoryOrd) FactoryOrdUpdate(m *model.FactoryOrd, forceColums ...string) (int64, error) {
  70. var (
  71. affected int64
  72. err error
  73. )
  74. if forceColums != nil {
  75. affected, err = factoryOrdOrdDb.Db.Where("out_order_no=?", factoryOrdOrdDb.OutOrderNo).Cols(forceColums...).Update(m)
  76. } else {
  77. affected, err = factoryOrdOrdDb.Db.Where("out_order_no=?", factoryOrdOrdDb.OutOrderNo).Update(m)
  78. }
  79. if err != nil {
  80. return 0, err
  81. }
  82. return affected, nil
  83. }
  84. type FactoryOrdWithUserIdentity struct {
  85. model.FactoryOrd `xorm:"extends"`
  86. model.UserIdentity `xorm:"extends"`
  87. model.Enterprise `xorm:"extends"`
  88. model.User `xorm:"extends"`
  89. model.FactoryDevice `xorm:"extends"`
  90. }
  91. func (FactoryOrdWithUserIdentity) TableName() string {
  92. return "factory_ord"
  93. }
  94. type FactoryOrdWithUserIdentityV2 struct {
  95. model.FactoryOrd `xorm:"extends"`
  96. model.Enterprise `xorm:"extends"`
  97. }
  98. func (FactoryOrdWithUserIdentityV2) TableName() string {
  99. return "factory_ord"
  100. }