package svc import ( "applet/app/admin/md" "applet/app/db" "applet/app/db/model" enum2 "applet/app/enum" "applet/app/utils" "fmt" ) func EnterpriseUserListByCentralKitchenForSchool(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) { //1、判断是否过滤 "教师" userIdentityDb := db.UserIdentityDb{} userIdentityDb.Set(0) teacherUserIdentities, err := userIdentityDb.FindUserIdentityForEnterpriseByIdentity(req.EnterpriseId, enum2.UserIdentityForCentralKitchenForTeacher) if err != nil { return } userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId) if err != nil { return } var teacherUserIdentitiesMap = map[string][]model.UserIdentity{} var userIdentitiesMap = map[string][]model.UserIdentity{} var uids, teacherUids []int for _, v := range *teacherUserIdentities { teacherUserIdentitiesMap[utils.IntToStr(v.Uid)] = append(teacherUserIdentitiesMap[utils.IntToStr(v.Uid)], v) teacherUids = append(teacherUids, v.Uid) } for _, v := range *userIdentities { userIdentitiesMap[utils.IntToStr(v.Uid)] = append(userIdentitiesMap[utils.IntToStr(v.Uid)], v) uids = append(uids, v.Uid) } var m []model.User sess := db.Db.In("id", uids) if req.IsTeacher == 1 { sess.In("id", teacherUids) } if req.IsTeacher == 2 { sess.NotIn("id", teacherUids) } if req.Nickname != "" { sess.And("nickname like ?", "%"+req.Nickname+"%") } if req.Phone != "" { sess.And("phone like ?", "%"+req.Phone+"%") } count, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) if err != nil { return } resp.Total = count classWithUserDb := db.ClassWithUserDb{} classWithUserDb.Set() for _, v := range m { temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{ Id: v.Id, Nickname: v.Nickname, Phone: v.Phone, Avatar: v.Avatar, IsTeacher: 0, CreateAt: v.CreateAt, } for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] { fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)]) //TODO::判断是否为老师 if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher { temp.UserIdentities = append(temp.UserIdentities, struct { Id int `json:"id" label:"身份id"` IdNo string `json:"id_no" label:"身份证号"` SchoolName string `json:"school_name" label:"学校名"` Name string `json:"name" label:"姓名"` Grade string `json:"grade" label:"年级"` GradeId int `json:"grade_id" label:"年级id"` Class string `json:"class" label:"班级"` ClassId int `json:"class_id" label:"班级id"` }{Id: v1.Id, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0}) temp.IsTeacher = 1 } else { data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id) if err2 != nil { return resp, err2 } if data == nil { continue } temp.UserIdentities = append(temp.UserIdentities, struct { Id int `json:"id" label:"身份id"` IdNo string `json:"id_no" label:"身份证号"` SchoolName string `json:"school_name" label:"学校名"` Name string `json:"name" label:"姓名"` Grade string `json:"grade" label:"年级"` GradeId int `json:"grade_id" label:"年级id"` Class string `json:"class" label:"班级"` ClassId int `json:"class_id" label:"班级id"` }{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}) } } resp.List = append(resp.List, temp) } return }