manual.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package data
  2. import (
  3. "eta/eta_mobile/models/data_manage"
  4. "eta/eta_mobile/models/system"
  5. "eta/eta_mobile/utils"
  6. "fmt"
  7. )
  8. func GetManualSysUser(keyWord string) (list []*data_manage.ManualSysUser, err error) {
  9. //departmentId := 1
  10. list = make([]*data_manage.ManualSysUser, 0)
  11. departmentItems, err := system.GetSysDepartmentAll()
  12. if err != nil {
  13. return list, err
  14. }
  15. for _, dv := range departmentItems {
  16. department := new(data_manage.ManualSysUser)
  17. department.ItemId = dv.DepartmentId * 10000
  18. department.ItemName = dv.DepartmentName
  19. fmt.Println(department.ItemId, department.ItemName)
  20. //GetSysuserList
  21. var condition string
  22. var pars []interface{}
  23. if keyWord != "" {
  24. condition += ` AND (real_name LIKE ? OR admin_name LIKE ? OR mobile LIKE ? ) `
  25. pars = utils.GetLikeKeywordPars(pars, keyWord, 3)
  26. }
  27. sysUsers, err := system.GetSysUserItems(condition, pars)
  28. if err != nil {
  29. return list, err
  30. }
  31. groups, err := system.GetSysGroupByDepartmentId(dv.DepartmentId)
  32. if err != nil {
  33. return list, err
  34. }
  35. dg := make([]*data_manage.ManualSysUser, 0)
  36. for _, v := range groups {
  37. group := new(data_manage.ManualSysUser)
  38. group.ItemId = v.DepartmentId * 100000
  39. group.ItemName = v.GroupName
  40. for _, sv := range sysUsers {
  41. user := new(data_manage.ManualSysUser)
  42. user.ItemId = sv.AdminId
  43. user.ItemName = sv.RealName
  44. if sv.GroupId == v.GroupId {
  45. group.Children = append(group.Children, user)
  46. }
  47. }
  48. if len(group.Children) > 0 {
  49. dg = append(dg, group)
  50. }
  51. }
  52. if len(groups) <= 0 {
  53. group := new(data_manage.ManualSysUser)
  54. group.ItemId = dv.DepartmentId * 100000
  55. group.ItemName = "无分组"
  56. for _, sv := range sysUsers {
  57. user := new(data_manage.ManualSysUser)
  58. user.ItemId = sv.AdminId
  59. user.ItemName = sv.RealName
  60. if sv.DepartmentId == dv.DepartmentId && sv.GroupId == 0 {
  61. group.Children = append(group.Children, user)
  62. }
  63. }
  64. if len(group.Children) > 0 {
  65. dg = append(dg, group)
  66. }
  67. }
  68. if len(dg) > 0 {
  69. department.Children = dg
  70. list = append(list, department)
  71. }
  72. }
  73. return
  74. }