面包店
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_scheme_with_enterprise.go 2.6 KiB

9 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type SchemeEnterpriseDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (adminRoleDb *SchemeEnterpriseDb) Set() { // set方法
  12. adminRoleDb.Db = Db
  13. }
  14. func (adminRoleDb *SchemeEnterpriseDb) FindSchemeEnterprise(schemeId int) (*[]model.SchemeWithEnterprise, error) {
  15. var m []model.SchemeWithEnterprise
  16. if err := adminRoleDb.Db.Where("scheme_id =?", schemeId).Find(&m); err != nil {
  17. return nil, logx.Error(err)
  18. }
  19. return &m, nil
  20. }
  21. func (adminRoleDb *SchemeEnterpriseDb) FindSchemeEnterpriseByEnterpriseId(id int) (*[]model.SchemeWithEnterprise, error) {
  22. var m []model.SchemeWithEnterprise
  23. if err := adminRoleDb.Db.Where("role_id =?", id).Find(&m); err != nil {
  24. return nil, logx.Error(err)
  25. }
  26. return &m, nil
  27. }
  28. func (adminRoleDb *SchemeEnterpriseDb) GetSchemeEnterpriseByEnterpriseId(enterpriseId int) (m *model.SchemeWithEnterprise, err error) {
  29. m = new(model.SchemeWithEnterprise)
  30. has, err := adminRoleDb.Db.Where("enterprise_id =?", enterpriseId).Get(m)
  31. if err != nil {
  32. return nil, logx.Error(err)
  33. }
  34. if has == false {
  35. return nil, nil
  36. }
  37. return m, nil
  38. }
  39. func (adminRoleDb *SchemeEnterpriseDb) GetSchemeEnterprise(id int) (m *model.SchemeWithEnterprise, err error) {
  40. m = new(model.SchemeWithEnterprise)
  41. has, err := adminRoleDb.Db.Where("id =?", id).Get(m)
  42. if err != nil {
  43. return nil, logx.Error(err)
  44. }
  45. if has == false {
  46. return nil, nil
  47. }
  48. return m, nil
  49. }
  50. func (adminRoleDb *SchemeEnterpriseDb) SchemeEnterpriseDeleteForEnterpriseBySession(session *xorm.Session, enterpriseId interface{}) (int64, error) {
  51. if reflect.TypeOf(enterpriseId).Kind() == reflect.Slice {
  52. return session.In("enterprise_id", enterpriseId).Delete(model.SchemeWithEnterprise{})
  53. } else {
  54. return session.Where("enterprise_id = ?", enterpriseId).Delete(model.SchemeWithEnterprise{})
  55. }
  56. }
  57. func (adminRoleDb *SchemeEnterpriseDb) SchemeEnterpriseDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  58. if reflect.TypeOf(id).Kind() == reflect.Slice {
  59. return session.In("scheme_id", id).Delete(model.SchemeWithEnterprise{})
  60. } else {
  61. return session.Where("scheme_id = ?", id).Delete(model.SchemeWithEnterprise{})
  62. }
  63. }
  64. func (adminRoleDb *SchemeEnterpriseDb) BatchAddSchemeEnterpriseBySession(session *xorm.Session, mm []*model.SchemeWithEnterprise) (int64, error) {
  65. affected, err := session.Insert(mm)
  66. if err != nil {
  67. return 0, err
  68. }
  69. return affected, nil
  70. }
  71. type SchemeEnterprise struct {
  72. model.Enterprise `xorm:"extends"`
  73. model.SchemeWithEnterprise `xorm:"extends"`
  74. }
  75. func (SchemeEnterprise) TableName() string {
  76. return "scheme_with_enterprise"
  77. }