智慧食堂
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 12 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. 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, EnterpriseId: v1.EnterpriseId, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: -1, ClassId: -1})
  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. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  89. IdNo string `json:"id_no" label:"身份证号"`
  90. SchoolName string `json:"school_name" label:"学校名"`
  91. Name string `json:"name" label:"姓名"`
  92. Grade string `json:"grade" label:"年级"`
  93. GradeId int `json:"grade_id" label:"年级id"`
  94. Class string `json:"class" label:"班级"`
  95. ClassId int `json:"class_id" label:"班级id"`
  96. }{Id: v1.Id, EnterpriseId: v1.EnterpriseId, 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})
  97. }
  98. }
  99. resp.List = append(resp.List, temp)
  100. }
  101. return
  102. }
  103. func EnterpriseUserListByCentralKitchenForSchoolV2(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) {
  104. sess := db.Db.Desc("user.id")
  105. if req.Nickname != "" {
  106. sess.And("user.nickname like ?", "%"+req.Nickname+"%")
  107. }
  108. if req.Phone != "" {
  109. sess.And("user.phone like ?", "%"+req.Phone+"%")
  110. }
  111. if req.IsTeacher == 1 {
  112. sess.And("user.phone like ?", "%"+req.Phone+"%")
  113. }
  114. if req.IsTeacher == 0 {
  115. sess.And("user_identity.identity = ? or user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent)
  116. }
  117. if req.IsTeacher == 1 {
  118. sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher)
  119. }
  120. if req.IsTeacher == 2 {
  121. sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForStudent)
  122. }
  123. userIdentityDb := db.UserIdentityDb{}
  124. userIdentityDb.Set(0)
  125. userIdentitiy, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
  126. if err != nil {
  127. return
  128. }
  129. var uids []int
  130. for _, v := range *userIdentitiy {
  131. uids = append(uids, v.Uid)
  132. }
  133. if len(uids) > 0 {
  134. sess.In("id", uids)
  135. }
  136. var classWithUserIdentityIdsOne []int
  137. var classWithUserIdentityIdsTwo []int
  138. classWithUserDb := db.ClassWithUserDb{}
  139. classWithUserDb.Set()
  140. if req.ClassId != 0 {
  141. classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId)
  142. if err2 != nil {
  143. return resp, err2
  144. }
  145. for _, v := range *classWithUsers {
  146. classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId)
  147. }
  148. }
  149. if req.GradeId != 0 {
  150. classDb := db.ClassDb{}
  151. classDb.Set(req.GradeId)
  152. classes, err3 := classDb.FindClass()
  153. if err3 != nil {
  154. return resp, err3
  155. }
  156. var classesId []int
  157. for _, v := range *classes {
  158. classesId = append(classesId, v.Id)
  159. }
  160. classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId)
  161. if err4 != nil {
  162. return resp, err4
  163. }
  164. for _, v := range *classWithUsers {
  165. classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId)
  166. }
  167. }
  168. if req.Name != "" {
  169. sess.And("user_identity.name like ?", "%"+req.Name+"%")
  170. }
  171. if len(classWithUserIdentityIdsOne) > 0 {
  172. sess.In("user_identity.id", classWithUserIdentityIdsOne)
  173. }
  174. if len(classWithUserIdentityIdsTwo) > 0 {
  175. sess.In("user_identity.id", classWithUserIdentityIdsTwo)
  176. }
  177. var m []*db.UserWithUserIdentity
  178. count, _ := sess.
  179. Join("LEFT", "user_identity", "user.id = user_identity.uid").
  180. Limit(req.Limit, (req.Page-1)*req.Limit).GroupBy("user.id").FindAndCount(&m)
  181. resp.Total = count
  182. var userIdentitiesMap = map[string][]db.UserIdentityWithClass{}
  183. for _, v := range m {
  184. userIdentityDb.Set(v.User.Id)
  185. userIdentities, err1 := userIdentityDb.FindUserIdentityWithClass()
  186. if err1 != nil {
  187. return resp, err1
  188. }
  189. for _, v1 := range *userIdentities {
  190. userIdentitiesMap[utils.IntToStr(v1.Uid)] = append(userIdentitiesMap[utils.IntToStr(v1.Uid)], v1)
  191. }
  192. }
  193. fmt.Println("!!!!!!!!!")
  194. for _, v := range m {
  195. temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
  196. Id: v.User.Id,
  197. IsTeacher: 0,
  198. }
  199. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.User.Id)] {
  200. temp.Nickname = v1.User.Nickname
  201. temp.Phone = v1.User.Phone
  202. temp.Avatar = v1.User.Avatar
  203. temp.CreateAt = v1.User.CreateAt
  204. //TODO::判断是否为老师
  205. if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
  206. temp.UserIdentities = append(temp.UserIdentities, struct {
  207. Id int `json:"id" label:"身份id"`
  208. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  209. IdNo string `json:"id_no" label:"身份证号"`
  210. SchoolName string `json:"school_name" label:"学校名"`
  211. Name string `json:"name" label:"姓名"`
  212. Grade string `json:"grade" label:"年级"`
  213. GradeId int `json:"grade_id" label:"年级id"`
  214. Class string `json:"class" label:"班级"`
  215. ClassId int `json:"class_id" label:"班级id"`
  216. }{Id: v1.UserIdentity.Id, EnterpriseId: v1.UserIdentity.EnterpriseId, IdNo: v1.IdNo, SchoolName: v1.Enterprise.Name, Name: v1.UserIdentity.Name, Grade: "教师", Class: "教师", GradeId: -1, ClassId: -1})
  217. temp.IsTeacher = 1
  218. }
  219. if v1.Identity == enum2.UserIdentityForCentralKitchenForStudent {
  220. temp.UserIdentities = append(temp.UserIdentities, struct {
  221. Id int `json:"id" label:"身份id"`
  222. EnterpriseId int `json:"enterprise_id" label:"企业id"`
  223. IdNo string `json:"id_no" label:"身份证号"`
  224. SchoolName string `json:"school_name" label:"学校名"`
  225. Name string `json:"name" label:"姓名"`
  226. Grade string `json:"grade" label:"年级"`
  227. GradeId int `json:"grade_id" label:"年级id"`
  228. Class string `json:"class" label:"班级"`
  229. ClassId int `json:"class_id" label:"班级id"`
  230. }{Id: v1.UserIdentity.Id, EnterpriseId: v1.UserIdentity.EnterpriseId, 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})
  231. }
  232. }
  233. resp.List = append(resp.List, temp)
  234. }
  235. resp.UserIdentityKindList = []map[string]interface{}{
  236. {
  237. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForStudent),
  238. "value": enum2.UserIdentityForCentralKitchenForStudent,
  239. },
  240. {
  241. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForTeacher),
  242. "value": enum2.UserIdentityForCentralKitchenForTeacher,
  243. },
  244. {
  245. "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForWorker),
  246. "value": enum2.UserIdentityForCentralKitchenForWorker,
  247. },
  248. {
  249. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForStudent),
  250. "value": enum2.UserIdentityForSelfSupportForStudent,
  251. },
  252. {
  253. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForTeacher),
  254. "value": enum2.UserIdentityForSelfSupportForTeacher,
  255. },
  256. {
  257. "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForWorker),
  258. "value": enum2.UserIdentityForSelfSupportForWorker,
  259. },
  260. }
  261. return
  262. }
  263. func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByNursingHomeResp, err error) {
  264. //1、判断是否过滤 "教师"
  265. userIdentityDb := db.UserIdentityDb{}
  266. userIdentityDb.Set(0)
  267. userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
  268. if err != nil {
  269. return
  270. }
  271. var userIdentitiesMap = map[string][]model.UserIdentity{}
  272. var uids []int
  273. for _, v := range *userIdentities {
  274. userIdentitiesMap[utils.IntToStr(v.Uid)] = append(userIdentitiesMap[utils.IntToStr(v.Uid)], v)
  275. uids = append(uids, v.Uid)
  276. }
  277. var m []model.User
  278. sess := db.Db.In("id", uids)
  279. if req.Nickname != "" {
  280. sess.And("nickname like ?", "%"+req.Nickname+"%")
  281. }
  282. if req.Phone != "" {
  283. sess.And("phone like ?", "%"+req.Phone+"%")
  284. }
  285. count, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)
  286. if err != nil {
  287. return
  288. }
  289. resp.Total = count
  290. for _, v := range m {
  291. temp := md.EnterpriseUserListByNursingHomeStruct{
  292. Id: v.Id,
  293. Nickname: v.Nickname,
  294. Phone: v.Phone,
  295. Avatar: v.Avatar,
  296. CreateAt: v.CreateAt,
  297. }
  298. for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
  299. temp.UserIdentities = append(temp.UserIdentities, struct {
  300. Id int `json:"id" label:"身份id"`
  301. IdNo string `json:"id_no" label:"身份证号"`
  302. EnterpriseName string `json:"enterprise_name" label:"单位名"`
  303. Name string `json:"name" label:"姓名"`
  304. }{Id: v1.Id, IdNo: v1.IdNo, EnterpriseName: req.EnterpriseName, Name: v1.Name})
  305. }
  306. resp.List = append(resp.List, temp)
  307. }
  308. return
  309. }