智慧食堂
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.

svc_enterprise_manage.go 3.7 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. enum2 "applet/app/enum"
  7. "applet/app/utils"
  8. "fmt"
  9. )
  10. func EnterpriseUserListByCentralKitchenForSchool(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) {
  11. //1、判断是否过滤 "教师"
  12. userIdentityDb := db.UserIdentityDb{}
  13. userIdentityDb.Set(0)
  14. teacherUserIdentities, err := userIdentityDb.FindUserIdentityForEnterpriseByIdentity(req.EnterpriseId, enum2.UserIdentityForCentralKitchenForTeacher)
  15. if err != nil {
  16. return
  17. }
  18. userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
  19. if err != nil {
  20. return
  21. }
  22. var teacherUserIdentitiesMap = map[string][]model.UserIdentity{}
  23. var userIdentitiesMap = map[string][]model.UserIdentity{}
  24. var uids, teacherUids []int
  25. for _, v := range *teacherUserIdentities {
  26. teacherUserIdentitiesMap[utils.IntToStr(v.Uid)] = append(teacherUserIdentitiesMap[utils.IntToStr(v.Uid)], v)
  27. teacherUids = append(teacherUids, v.Uid)
  28. }
  29. for _, v := range *userIdentities {
  30. userIdentitiesMap[utils.IntToStr(v.Uid)] = append(userIdentitiesMap[utils.IntToStr(v.Uid)], v)
  31. uids = append(uids, v.Uid)
  32. }
  33. var m []model.User
  34. sess := db.Db.In("id", uids)
  35. if req.IsTeacher == 1 {
  36. sess.In("id", teacherUids)
  37. }
  38. if req.IsTeacher == 2 {
  39. sess.NotIn("id", teacherUids)
  40. }
  41. if req.Nickname != "" {
  42. sess.And("nickname like ?", "%"+req.Nickname+"%")
  43. }
  44. if req.Phone != "" {
  45. sess.And("phone like ?", "%"+req.Phone+"%")
  46. }
  47. count, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)
  48. if err != nil {
  49. return
  50. }
  51. resp.Total = count
  52. classWithUserDb := db.ClassWithUserDb{}
  53. classWithUserDb.Set()
  54. for _, v := range m {
  55. temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
  56. Id: v.Id,
  57. Nickname: v.Nickname,
  58. Phone: v.Phone,
  59. Avatar: v.Avatar,
  60. IsTeacher: 0,
  61. CreateAt: v.CreateAt,
  62. }
  63. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
  64. fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)])
  65. //TODO::判断是否为老师
  66. if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
  67. temp.UserIdentities = append(temp.UserIdentities, struct {
  68. Id int `json:"id" label:"身份id"`
  69. IdNo string `json:"id_no" label:"身份证号"`
  70. SchoolName string `json:"school_name" label:"学校名"`
  71. Name string `json:"name" label:"姓名"`
  72. Grade string `json:"grade" label:"年级"`
  73. GradeId int `json:"grade_id" label:"年级id"`
  74. Class string `json:"class" label:"班级"`
  75. ClassId int `json:"class_id" label:"班级id"`
  76. }{Id: v1.Id, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0})
  77. temp.IsTeacher = 1
  78. } else {
  79. data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id)
  80. if err2 != nil {
  81. return resp, err2
  82. }
  83. if data == nil {
  84. continue
  85. }
  86. temp.UserIdentities = append(temp.UserIdentities, struct {
  87. Id int `json:"id" label:"身份id"`
  88. IdNo string `json:"id_no" label:"身份证号"`
  89. SchoolName string `json:"school_name" label:"学校名"`
  90. Name string `json:"name" label:"姓名"`
  91. Grade string `json:"grade" label:"年级"`
  92. GradeId int `json:"grade_id" label:"年级id"`
  93. Class string `json:"class" label:"班级"`
  94. ClassId int `json:"class_id" label:"班级id"`
  95. }{Id: v1.Id, IdNo: data.UserIdentity.IdNo, SchoolName: data.Enterprise.Name, Name: data.UserIdentity.Name, Grade: data.Grade.Name, Class: data.Class.Name, GradeId: data.Grade.Id, ClassId: data.Class.Id})
  96. }
  97. }
  98. resp.List = append(resp.List, temp)
  99. }
  100. return
  101. }