智慧食堂
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 8.6 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
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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, err := 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. var userIdentitiesMap = map[string][]db.UserIdentityWithClass{}
  126. userIdentityDb := db.UserIdentityDb{}
  127. for _, v := range m {
  128. userIdentityDb.Set(v.User.Id)
  129. userIdentities, err1 := userIdentityDb.FindUserIdentityWithClass()
  130. if err1 != nil {
  131. return resp, err1
  132. }
  133. for _, v1 := range *userIdentities {
  134. userIdentitiesMap[utils.IntToStr(v1.Uid)] = append(userIdentitiesMap[utils.IntToStr(v1.Uid)], v1)
  135. }
  136. }
  137. fmt.Println("!!!!!!!!!")
  138. resp.Total = count
  139. classWithUserDb := db.ClassWithUserDb{}
  140. classWithUserDb.Set()
  141. for _, v := range m {
  142. temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
  143. Id: v.User.Id,
  144. Nickname: v.Nickname,
  145. Phone: v.Phone,
  146. Avatar: v.Avatar,
  147. IsTeacher: 0,
  148. CreateAt: v.User.CreateAt,
  149. }
  150. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.User.Id)] {
  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. }