智慧食堂
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

381 строка
14 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. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  69. IdNo string `json:"id_no" label:"身份证号"`
  70. CertType int `json:"cert_type" label:"证件类型"`
  71. SchoolName string `json:"school_name" label:"学校名"`
  72. Name string `json:"name" label:"姓名"`
  73. Grade string `json:"grade" label:"年级"`
  74. GradeId int `json:"grade_id" label:"年级id"`
  75. Class string `json:"class" label:"班级"`
  76. ClassId int `json:"class_id" label:"班级id"`
  77. }{Id: v1.Id, EnterpriseId: v1.EnterpriseId, IdNo: v1.IdNo, CertType: v1.CertType, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: -1, ClassId: -1})
  78. temp.IsTeacher = 1
  79. } else {
  80. data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id)
  81. if err2 != nil {
  82. return resp, err2
  83. }
  84. if data == nil {
  85. continue
  86. }
  87. temp.UserIdentities = append(temp.UserIdentities, struct {
  88. Id int `json:"id" label:"身份id"`
  89. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  90. IdNo string `json:"id_no" label:"身份证号"`
  91. CertType int `json:"cert_type" label:"证件类型"`
  92. SchoolName string `json:"school_name" label:"学校名"`
  93. Name string `json:"name" label:"姓名"`
  94. Grade string `json:"grade" label:"年级"`
  95. GradeId int `json:"grade_id" label:"年级id"`
  96. Class string `json:"class" label:"班级"`
  97. ClassId int `json:"class_id" label:"班级id"`
  98. }{Id: v1.Id, EnterpriseId: v1.EnterpriseId, IdNo: data.UserIdentity.IdNo, CertType: data.UserIdentity.CertType, SchoolName: data.Enterprise.Name, Name: data.UserIdentity.Name, Grade: data.Grade.Name, Class: data.Class.Name, GradeId: data.Grade.Id, ClassId: data.Class.Id})
  99. }
  100. }
  101. resp.List = append(resp.List, temp)
  102. }
  103. resp.UserIdentityKindList = []map[string]interface{}{
  104. {
  105. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForStudent),
  106. "value": enum2.UserIdentityForCentralKitchenForStudent,
  107. },
  108. {
  109. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForTeacher),
  110. "value": enum2.UserIdentityForCentralKitchenForTeacher,
  111. },
  112. {
  113. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForWorker),
  114. "value": enum2.UserIdentityForCentralKitchenForWorker,
  115. },
  116. {
  117. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForStudent),
  118. "value": enum2.UserIdentityForSelfSupportForStudent,
  119. },
  120. {
  121. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForTeacher),
  122. "value": enum2.UserIdentityForSelfSupportForTeacher,
  123. },
  124. {
  125. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForWorker),
  126. "value": enum2.UserIdentityForSelfSupportForWorker,
  127. },
  128. }
  129. resp.UserIdentityCertTypeList = []map[string]interface{}{
  130. {
  131. "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForIdCard),
  132. "value": enum2.UserIdentityCertTypeForIdCard,
  133. },
  134. {
  135. "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForStudentId),
  136. "value": enum2.UserIdentityCertTypeForStudentId,
  137. },
  138. //{
  139. // "name": enum.UserIdentityCertType.String(enum.UserIdentityCertTypeForPassport),
  140. // "value": enum.UserIdentityCertTypeForPassport,
  141. //},
  142. }
  143. return
  144. }
  145. func EnterpriseUserListByCentralKitchenForSchoolV2(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) {
  146. sess := db.Db.Desc("user.id")
  147. if req.Nickname != "" {
  148. sess.And("user.nickname like ?", "%"+req.Nickname+"%")
  149. }
  150. if req.Phone != "" {
  151. sess.And("user.phone like ?", "%"+req.Phone+"%")
  152. }
  153. if req.IsTeacher == 1 {
  154. sess.And("user.phone like ?", "%"+req.Phone+"%")
  155. }
  156. if req.IsTeacher == 0 {
  157. sess.And("user_identity.identity = ? or user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent)
  158. }
  159. if req.IsTeacher == 1 {
  160. sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher)
  161. }
  162. if req.IsTeacher == 2 {
  163. sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForStudent)
  164. }
  165. userIdentityDb := db.UserIdentityDb{}
  166. userIdentityDb.Set(0)
  167. userIdentitiy, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
  168. if err != nil {
  169. return
  170. }
  171. var uids []int
  172. for _, v := range *userIdentitiy {
  173. uids = append(uids, v.Uid)
  174. }
  175. if len(uids) > 0 {
  176. sess.In("id", uids)
  177. }
  178. var classWithUserIdentityIdsOne []int
  179. var classWithUserIdentityIdsTwo []int
  180. classWithUserDb := db.ClassWithUserDb{}
  181. classWithUserDb.Set()
  182. if req.ClassId != 0 {
  183. classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId)
  184. if err2 != nil {
  185. return resp, err2
  186. }
  187. for _, v := range *classWithUsers {
  188. classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId)
  189. }
  190. }
  191. if req.GradeId != 0 {
  192. classDb := db.ClassDb{}
  193. classDb.Set(req.GradeId)
  194. classes, err3 := classDb.FindClass()
  195. if err3 != nil {
  196. return resp, err3
  197. }
  198. var classesId []int
  199. for _, v := range *classes {
  200. classesId = append(classesId, v.Id)
  201. }
  202. classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId)
  203. if err4 != nil {
  204. return resp, err4
  205. }
  206. for _, v := range *classWithUsers {
  207. classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId)
  208. }
  209. }
  210. if req.Name != "" {
  211. sess.And("user_identity.name like ?", "%"+req.Name+"%")
  212. }
  213. if len(classWithUserIdentityIdsOne) > 0 {
  214. sess.In("user_identity.id", classWithUserIdentityIdsOne)
  215. }
  216. if len(classWithUserIdentityIdsTwo) > 0 {
  217. sess.In("user_identity.id", classWithUserIdentityIdsTwo)
  218. }
  219. var m []*db.UserWithUserIdentity
  220. count, _ := sess.
  221. Join("LEFT", "user_identity", "user.id = user_identity.uid").
  222. Limit(req.Limit, (req.Page-1)*req.Limit).GroupBy("user.id").FindAndCount(&m)
  223. resp.Total = count
  224. var userIdentitiesMap = map[string][]db.UserIdentityWithClass{}
  225. for _, v := range m {
  226. userIdentityDb.Set(v.User.Id)
  227. userIdentities, err1 := userIdentityDb.FindUserIdentityWithClass()
  228. if err1 != nil {
  229. return resp, err1
  230. }
  231. for _, v1 := range *userIdentities {
  232. userIdentitiesMap[utils.IntToStr(v1.Uid)] = append(userIdentitiesMap[utils.IntToStr(v1.Uid)], v1)
  233. }
  234. }
  235. fmt.Println("!!!!!!!!!")
  236. for _, v := range m {
  237. temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
  238. Id: v.User.Id,
  239. IsTeacher: 0,
  240. }
  241. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.User.Id)] {
  242. temp.Nickname = v1.User.Nickname
  243. temp.Phone = v1.User.Phone
  244. temp.Avatar = v1.User.Avatar
  245. temp.CreateAt = v1.User.CreateAt
  246. //TODO::判断是否为老师
  247. if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
  248. temp.UserIdentities = append(temp.UserIdentities, struct {
  249. Id int `json:"id" label:"身份id"`
  250. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  251. IdNo string `json:"id_no" label:"身份证号"`
  252. CertType int `json:"cert_type" label:"证件类型"`
  253. SchoolName string `json:"school_name" label:"学校名"`
  254. Name string `json:"name" label:"姓名"`
  255. Grade string `json:"grade" label:"年级"`
  256. GradeId int `json:"grade_id" label:"年级id"`
  257. Class string `json:"class" label:"班级"`
  258. ClassId int `json:"class_id" label:"班级id"`
  259. }{Id: v1.UserIdentity.Id, EnterpriseId: v1.UserIdentity.EnterpriseId, IdNo: v1.IdNo, CertType: v1.CertType, SchoolName: v1.Enterprise.Name, Name: v1.UserIdentity.Name, Grade: "教师", Class: "教师", GradeId: -1, ClassId: -1})
  260. temp.IsTeacher = 1
  261. }
  262. if v1.Identity == enum2.UserIdentityForCentralKitchenForStudent {
  263. temp.UserIdentities = append(temp.UserIdentities, struct {
  264. Id int `json:"id" label:"身份id"`
  265. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  266. IdNo string `json:"id_no" label:"身份证号"`
  267. CertType int `json:"cert_type" label:"证件类型"`
  268. SchoolName string `json:"school_name" label:"学校名"`
  269. Name string `json:"name" label:"姓名"`
  270. Grade string `json:"grade" label:"年级"`
  271. GradeId int `json:"grade_id" label:"年级id"`
  272. Class string `json:"class" label:"班级"`
  273. ClassId int `json:"class_id" label:"班级id"`
  274. }{Id: v1.UserIdentity.Id, EnterpriseId: v1.UserIdentity.EnterpriseId, IdNo: v1.UserIdentity.IdNo, CertType: v1.UserIdentity.CertType, SchoolName: v1.Enterprise.Name, Name: v1.UserIdentity.Name, Grade: v1.Grade.Name, Class: v1.Class.Name, GradeId: v1.Grade.Id, ClassId: v1.Class.Id})
  275. }
  276. }
  277. resp.List = append(resp.List, temp)
  278. }
  279. resp.UserIdentityKindList = []map[string]interface{}{
  280. {
  281. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForStudent),
  282. "value": enum2.UserIdentityForCentralKitchenForStudent,
  283. },
  284. {
  285. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForTeacher),
  286. "value": enum2.UserIdentityForCentralKitchenForTeacher,
  287. },
  288. {
  289. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForWorker),
  290. "value": enum2.UserIdentityForCentralKitchenForWorker,
  291. },
  292. {
  293. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForStudent),
  294. "value": enum2.UserIdentityForSelfSupportForStudent,
  295. },
  296. {
  297. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForTeacher),
  298. "value": enum2.UserIdentityForSelfSupportForTeacher,
  299. },
  300. {
  301. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForWorker),
  302. "value": enum2.UserIdentityForSelfSupportForWorker,
  303. },
  304. }
  305. resp.UserIdentityCertTypeList = []map[string]interface{}{
  306. {
  307. "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForIdCard),
  308. "value": enum2.UserIdentityCertTypeForIdCard,
  309. },
  310. {
  311. "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForStudentId),
  312. "value": enum2.UserIdentityCertTypeForStudentId,
  313. },
  314. //{
  315. // "name": enum.UserIdentityCertType.String(enum.UserIdentityCertTypeForPassport),
  316. // "value": enum.UserIdentityCertTypeForPassport,
  317. //},
  318. }
  319. return
  320. }
  321. func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByNursingHomeResp, err error) {
  322. //1、判断是否过滤 "教师"
  323. userIdentityDb := db.UserIdentityDb{}
  324. userIdentityDb.Set(0)
  325. userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
  326. if err != nil {
  327. return
  328. }
  329. var userIdentitiesMap = map[string][]model.UserIdentity{}
  330. var uids []int
  331. for _, v := range *userIdentities {
  332. userIdentitiesMap[utils.IntToStr(v.Uid)] = append(userIdentitiesMap[utils.IntToStr(v.Uid)], v)
  333. uids = append(uids, v.Uid)
  334. }
  335. var m []model.User
  336. sess := db.Db.In("id", uids)
  337. if req.Nickname != "" {
  338. sess.And("nickname like ?", "%"+req.Nickname+"%")
  339. }
  340. if req.Phone != "" {
  341. sess.And("phone like ?", "%"+req.Phone+"%")
  342. }
  343. count, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)
  344. if err != nil {
  345. return
  346. }
  347. resp.Total = count
  348. for _, v := range m {
  349. temp := md.EnterpriseUserListByNursingHomeStruct{
  350. Id: v.Id,
  351. Nickname: v.Nickname,
  352. Phone: v.Phone,
  353. Avatar: v.Avatar,
  354. CreateAt: v.CreateAt,
  355. }
  356. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
  357. temp.UserIdentities = append(temp.UserIdentities, struct {
  358. Id int `json:"id" label:"身份id"`
  359. IdNo string `json:"id_no" label:"身份证号"`
  360. EnterpriseName string `json:"enterprise_name" label:"单位名"`
  361. Name string `json:"name" label:"姓名"`
  362. }{Id: v1.Id, IdNo: v1.IdNo, EnterpriseName: req.EnterpriseName, Name: v1.Name})
  363. }
  364. resp.List = append(resp.List, temp)
  365. }
  366. return
  367. }