admin.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package models
  2. import (
  3. "eta_gn/eta_task/global"
  4. "fmt"
  5. "strings"
  6. )
  7. type Admin struct {
  8. AdminId int `gorm:"primaryKey;autoIncrement;column:admin_id"`
  9. AdminName string `description:"系统用户名称"`
  10. RealName string `description:"系统用户姓名"`
  11. Password string `description:"密码"`
  12. Mobile string `description:"手机号"`
  13. RoleId int `description:"角色id"`
  14. RoleName string `description:"角色名称"`
  15. RoleTypeCode string `description:"角色编码"`
  16. DepartmentId int `description:"部门id"`
  17. GroupId int `description:"分组id"`
  18. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
  19. Position string `description:"职位"`
  20. OpenId string `description:"弘则部门公众号的openid"`
  21. OutId string `description:"外部ID"`
  22. }
  23. func GetAdminByAdminId(adminId int) (item *Admin, err error) {
  24. //sql := `SELECT * FROM admin WHERE admin_id=? `
  25. //err = orm.NewOrm().Raw(sql, adminId).QueryRow(&item)
  26. sql := `SELECT * FROM "admin" WHERE admin_id=? `
  27. err = global.DmSQL["eta"].Raw(sql, adminId).Find(&item).Error
  28. return
  29. }
  30. func (m *Admin) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Admin, err error) {
  31. fields := strings.Join(fieldArr, ",")
  32. if len(fieldArr) == 0 {
  33. fields = `*`
  34. }
  35. order := `ORDER BY created_time DESC`
  36. if orderRule != "" {
  37. order = ` ORDER BY ` + orderRule
  38. }
  39. sql := fmt.Sprintf(`SELECT %s FROM "admin" WHERE 1=1 %s %s`, fields, condition, order)
  40. err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error
  41. return
  42. }