广告平台(总站长使用)
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

78 linhas
2.2 KiB

  1. package implement
  2. import (
  3. "applet/app/db/dao"
  4. "applet/app/db/model"
  5. "applet/app/utils/logx"
  6. "reflect"
  7. "xorm.io/xorm"
  8. )
  9. func NewMediumWithRoleDb(engine *xorm.Engine) dao.MediumWithRoleDao {
  10. return &MediumWithRoleDb{Db: engine}
  11. }
  12. type MediumWithRoleDb struct {
  13. Db *xorm.Engine
  14. }
  15. func (m MediumWithRoleDb) FindMediumWithRole(id int) (*[]model.MediumWithRole, error) {
  16. var mm []model.MediumWithRole
  17. if err := m.Db.Where("adm_id =?", id).Find(&mm); err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. return &mm, nil
  21. }
  22. func (m MediumWithRoleDb) FindMediumWithRoleByRoleId(id int) (*[]model.MediumWithRole, error) {
  23. var mm []model.MediumWithRole
  24. if err := m.Db.Where("role_id =?", id).Find(&mm); err != nil {
  25. return nil, logx.Error(err)
  26. }
  27. return &mm, nil
  28. }
  29. func (m MediumWithRoleDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
  30. if reflect.TypeOf(admId).Kind() == reflect.Slice {
  31. return session.In("adm_id", admId).Delete(model.MediumWithRole{})
  32. } else {
  33. return session.Where("adm_id = ?", admId).Delete(model.MediumWithRole{})
  34. }
  35. }
  36. func (m MediumWithRoleDb) GetMediumWithRoleByRole(id int) (mm *model.MediumWithRole, err error) {
  37. mm = new(model.MediumWithRole)
  38. has, err := m.Db.Where("role_id =?", id).Get(mm)
  39. if err != nil {
  40. return nil, logx.Error(err)
  41. }
  42. if has == false {
  43. return nil, nil
  44. }
  45. return mm, nil
  46. }
  47. func (m MediumWithRoleDb) MediumWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  48. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  49. return session.In("role_id", roleId).Delete(model.MediumWithRole{})
  50. } else {
  51. return session.Where("role_id = ?", roleId).Delete(model.MediumWithRole{})
  52. }
  53. }
  54. func (m MediumWithRoleDb) MediumWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  55. if reflect.TypeOf(id).Kind() == reflect.Slice {
  56. return session.In("medium_id", id).Delete(model.MediumWithRole{})
  57. } else {
  58. return session.Where("medium_id = ?", id).Delete(model.MediumWithRole{})
  59. }
  60. }
  61. func (m MediumWithRoleDb) BatchAddMediumWithRoleBySession(session *xorm.Session, mm []*model.MediumWithRole) (int64, error) {
  62. affected, err := session.Insert(mm)
  63. if err != nil {
  64. return 0, err
  65. }
  66. return affected, nil
  67. }