广告平台(总站长使用)
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.
 
 
 
 
 
 

78 lines
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 NewAgentWithRoleDb(engine *xorm.Engine) dao.AgentWithRoleDao {
  10. return &AgentWithRoleDb{Db: engine}
  11. }
  12. type AgentWithRoleDb struct {
  13. Db *xorm.Engine
  14. }
  15. func (a AgentWithRoleDb) FindAgentWithRole(id int) (*[]model.AgentWithRole, error) {
  16. var mm []model.AgentWithRole
  17. if err := a.Db.Where("adm_id =?", id).Find(&mm); err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. return &mm, nil
  21. }
  22. func (a AgentWithRoleDb) FindAgentWithRoleByRoleId(id int) (*[]model.AgentWithRole, error) {
  23. var mm []model.AgentWithRole
  24. if err := a.Db.Where("role_id =?", id).Find(&mm); err != nil {
  25. return nil, logx.Error(err)
  26. }
  27. return &mm, nil
  28. }
  29. func (a AgentWithRoleDb) 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.AgentWithRole{})
  32. } else {
  33. return session.Where("adm_id = ?", admId).Delete(model.AgentWithRole{})
  34. }
  35. }
  36. func (a AgentWithRoleDb) GetAgentWithRoleByRole(id int) (mm *model.AgentWithRole, err error) {
  37. mm = new(model.AgentWithRole)
  38. has, err := a.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 (a AgentWithRoleDb) AgentWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  48. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  49. return session.In("role_id", roleId).Delete(model.AgentWithRole{})
  50. } else {
  51. return session.Where("role_id = ?", roleId).Delete(model.AgentWithRole{})
  52. }
  53. }
  54. func (a AgentWithRoleDb) AgentWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  55. if reflect.TypeOf(id).Kind() == reflect.Slice {
  56. return session.In("agent_id", id).Delete(model.AgentWithRole{})
  57. } else {
  58. return session.Where("agent_id = ?", id).Delete(model.AgentWithRole{})
  59. }
  60. }
  61. func (a AgentWithRoleDb) BatchAddAgentWithRoleBySession(session *xorm.Session, mm []*model.AgentWithRole) (int64, error) {
  62. affected, err := session.Insert(mm)
  63. if err != nil {
  64. return 0, err
  65. }
  66. return affected, nil
  67. }