智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

236 行
8.7 KiB

  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. //TODO::判断是否为老师
  65. if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
  66. temp.UserIdentities = append(temp.UserIdentities, struct {
  67. Id int `json:"id" label:"身份id"`
  68. IdNo string `json:"id_no" label:"身份证号"`
  69. SchoolName string `json:"school_name" label:"学校名"`
  70. Name string `json:"name" label:"姓名"`
  71. Grade string `json:"grade" label:"年级"`
  72. GradeId int `json:"grade_id" label:"年级id"`
  73. Class string `json:"class" label:"班级"`
  74. ClassId int `json:"class_id" label:"班级id"`
  75. }{Id: v1.Id, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0})
  76. temp.IsTeacher = 1
  77. } else {
  78. data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id)
  79. if err2 != nil {
  80. return resp, err2
  81. }
  82. if data == nil {
  83. continue
  84. }
  85. temp.UserIdentities = append(temp.UserIdentities, struct {
  86. Id int `json:"id" label:"身份id"`
  87. IdNo string `json:"id_no" label:"身份证号"`
  88. SchoolName string `json:"school_name" label:"学校名"`
  89. Name string `json:"name" label:"姓名"`
  90. Grade string `json:"grade" label:"年级"`
  91. GradeId int `json:"grade_id" label:"年级id"`
  92. Class string `json:"class" label:"班级"`
  93. ClassId int `json:"class_id" label:"班级id"`
  94. }{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})
  95. }
  96. }
  97. resp.List = append(resp.List, temp)
  98. }
  99. return
  100. }
  101. func EnterpriseUserListByCentralKitchenForSchoolV2(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) {
  102. sess := db.Db.Desc("user.id")
  103. if req.Nickname != "" {
  104. sess.And("user.nickname like ?", "%"+req.Nickname+"%")
  105. }
  106. if req.Phone != "" {
  107. sess.And("user.phone like ?", "%"+req.Phone+"%")
  108. }
  109. if req.IsTeacher == 1 {
  110. sess.And("user.phone like ?", "%"+req.Phone+"%")
  111. }
  112. if req.IsTeacher == 0 {
  113. sess.And("user_identity.identity = ? or user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent)
  114. }
  115. if req.IsTeacher == 1 {
  116. sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher)
  117. }
  118. if req.IsTeacher == 2 {
  119. sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForStudent)
  120. }
  121. var m []*db.UserWithUserIdentity
  122. count, _ := sess.
  123. Join("LEFT", "user_identity", "user.id = user_identity.uid").
  124. Limit(req.Limit, (req.Page-1)*req.Limit).GroupBy("user.id").FindAndCount(&m)
  125. resp.Total = count
  126. var userIdentitiesMap = map[string][]db.UserIdentityWithClass{}
  127. userIdentityDb := db.UserIdentityDb{}
  128. for _, v := range m {
  129. userIdentityDb.Set(v.User.Id)
  130. userIdentities, err1 := userIdentityDb.FindUserIdentityWithClass()
  131. if err1 != nil {
  132. return resp, err1
  133. }
  134. for _, v1 := range *userIdentities {
  135. userIdentitiesMap[utils.IntToStr(v1.Uid)] = append(userIdentitiesMap[utils.IntToStr(v1.Uid)], v1)
  136. }
  137. }
  138. fmt.Println("!!!!!!!!!")
  139. classWithUserDb := db.ClassWithUserDb{}
  140. classWithUserDb.Set()
  141. for _, v := range m {
  142. temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
  143. Id: v.User.Id,
  144. IsTeacher: 0,
  145. }
  146. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.User.Id)] {
  147. temp.Nickname = v1.User.Nickname
  148. temp.Phone = v1.User.Phone
  149. temp.Avatar = v1.User.Avatar
  150. temp.CreateAt = v1.User.CreateAt
  151. //TODO::判断是否为老师
  152. if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
  153. temp.UserIdentities = append(temp.UserIdentities, struct {
  154. Id int `json:"id" label:"身份id"`
  155. IdNo string `json:"id_no" label:"身份证号"`
  156. SchoolName string `json:"school_name" label:"学校名"`
  157. Name string `json:"name" label:"姓名"`
  158. Grade string `json:"grade" label:"年级"`
  159. GradeId int `json:"grade_id" label:"年级id"`
  160. Class string `json:"class" label:"班级"`
  161. ClassId int `json:"class_id" label:"班级id"`
  162. }{Id: v1.UserIdentity.Id, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.UserIdentity.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0})
  163. temp.IsTeacher = 1
  164. }
  165. if v1.Identity == enum2.UserIdentityForCentralKitchenForStudent {
  166. temp.UserIdentities = append(temp.UserIdentities, struct {
  167. Id int `json:"id" label:"身份id"`
  168. IdNo string `json:"id_no" label:"身份证号"`
  169. SchoolName string `json:"school_name" label:"学校名"`
  170. Name string `json:"name" label:"姓名"`
  171. Grade string `json:"grade" label:"年级"`
  172. GradeId int `json:"grade_id" label:"年级id"`
  173. Class string `json:"class" label:"班级"`
  174. ClassId int `json:"class_id" label:"班级id"`
  175. }{Id: v1.UserIdentity.Id, IdNo: v1.UserIdentity.IdNo, SchoolName: v1.Enterprise.Name, Name: v1.UserIdentity.Name, Grade: v1.Grade.Name, Class: v1.Class.Name, GradeId: v1.Grade.Id, ClassId: v1.Class.Id})
  176. }
  177. }
  178. resp.List = append(resp.List, temp)
  179. }
  180. return
  181. }
  182. func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByNursingHomeResp, err error) {
  183. //1、判断是否过滤 "教师"
  184. userIdentityDb := db.UserIdentityDb{}
  185. userIdentityDb.Set(0)
  186. userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
  187. if err != nil {
  188. return
  189. }
  190. var userIdentitiesMap = map[string][]model.UserIdentity{}
  191. var uids []int
  192. for _, v := range *userIdentities {
  193. userIdentitiesMap[utils.IntToStr(v.Uid)] = append(userIdentitiesMap[utils.IntToStr(v.Uid)], v)
  194. uids = append(uids, v.Uid)
  195. }
  196. var m []model.User
  197. sess := db.Db.In("id", uids)
  198. if req.Nickname != "" {
  199. sess.And("nickname like ?", "%"+req.Nickname+"%")
  200. }
  201. if req.Phone != "" {
  202. sess.And("phone like ?", "%"+req.Phone+"%")
  203. }
  204. count, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)
  205. if err != nil {
  206. return
  207. }
  208. resp.Total = count
  209. for _, v := range m {
  210. temp := md.EnterpriseUserListByNursingHomeStruct{
  211. Id: v.Id,
  212. Nickname: v.Nickname,
  213. Phone: v.Phone,
  214. Avatar: v.Avatar,
  215. CreateAt: v.CreateAt,
  216. }
  217. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
  218. temp.UserIdentities = append(temp.UserIdentities, struct {
  219. Id int `json:"id" label:"身份id"`
  220. IdNo string `json:"id_no" label:"身份证号"`
  221. EnterpriseName string `json:"enterprise_name" label:"单位名"`
  222. Name string `json:"name" label:"姓名"`
  223. }{Id: v1.Id, IdNo: v1.IdNo, EnterpriseName: req.EnterpriseName, Name: v1.Name})
  224. }
  225. resp.List = append(resp.List, temp)
  226. }
  227. return
  228. }