manual.go 2.0 KB

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