|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- 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)] {
- //TODO::判断是否为老师
- if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
- temp.UserIdentities = append(temp.UserIdentities, struct {
- Id int `json:"id" label:"身份id"`
- EnterpriseId int `json:"enterprise_id" label:"企业id"`
- IdNo string `json:"id_no" label:"身份证号"`
- CertType int `json:"cert_type" 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, EnterpriseId: v1.EnterpriseId, IdNo: v1.IdNo, CertType: v1.CertType, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: -1, ClassId: -1})
- 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"`
- EnterpriseId int `json:"enterprise_id" label:"企业id"`
- IdNo string `json:"id_no" label:"身份证号"`
- CertType int `json:"cert_type" 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, 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})
- }
- }
- resp.List = append(resp.List, temp)
- }
-
- resp.UserIdentityKindList = []map[string]interface{}{
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForStudent),
- "value": enum2.UserIdentityForCentralKitchenForStudent,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForTeacher),
- "value": enum2.UserIdentityForCentralKitchenForTeacher,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForWorker),
- "value": enum2.UserIdentityForCentralKitchenForWorker,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForStudent),
- "value": enum2.UserIdentityForSelfSupportForStudent,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForTeacher),
- "value": enum2.UserIdentityForSelfSupportForTeacher,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForWorker),
- "value": enum2.UserIdentityForSelfSupportForWorker,
- },
- }
- resp.UserIdentityCertTypeList = []map[string]interface{}{
- {
- "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForIdCard),
- "value": enum2.UserIdentityCertTypeForIdCard,
- },
- {
- "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForStudentId),
- "value": enum2.UserIdentityCertTypeForStudentId,
- },
- //{
- // "name": enum.UserIdentityCertType.String(enum.UserIdentityCertTypeForPassport),
- // "value": enum.UserIdentityCertTypeForPassport,
- //},
- }
- return
- }
-
- func EnterpriseUserListByCentralKitchenForSchoolV2(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) {
- sess := db.Db.Desc("user.id")
- if req.Nickname != "" {
- sess.And("user.nickname like ?", "%"+req.Nickname+"%")
- }
- if req.Phone != "" {
- sess.And("user.phone like ?", "%"+req.Phone+"%")
- }
- if req.IsTeacher == 1 {
- sess.And("user.phone like ?", "%"+req.Phone+"%")
- }
- if req.IsTeacher == 0 {
- sess.And("user_identity.identity = ? or user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent)
- }
- if req.IsTeacher == 1 {
- sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher)
- }
- if req.IsTeacher == 2 {
- sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForStudent)
- }
-
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(0)
- userIdentitiy, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
- if err != nil {
- return
- }
- var uids []int
- for _, v := range *userIdentitiy {
- uids = append(uids, v.Uid)
- }
- if len(uids) > 0 {
- sess.In("id", uids)
- }
-
- var classWithUserIdentityIdsOne []int
- var classWithUserIdentityIdsTwo []int
- classWithUserDb := db.ClassWithUserDb{}
- classWithUserDb.Set()
- if req.ClassId != 0 {
- classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId)
- if err2 != nil {
- return resp, err2
- }
- for _, v := range *classWithUsers {
- classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId)
- }
- }
- if req.GradeId != 0 {
- classDb := db.ClassDb{}
- classDb.Set(req.GradeId)
- classes, err3 := classDb.FindClass()
- if err3 != nil {
- return resp, err3
- }
- var classesId []int
- for _, v := range *classes {
- classesId = append(classesId, v.Id)
- }
- classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId)
- if err4 != nil {
- return resp, err4
- }
- for _, v := range *classWithUsers {
- classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId)
- }
- }
-
- if req.Name != "" {
- sess.And("user_identity.name like ?", "%"+req.Name+"%")
- }
- if len(classWithUserIdentityIdsOne) > 0 {
- sess.In("user_identity.id", classWithUserIdentityIdsOne)
- }
- if len(classWithUserIdentityIdsTwo) > 0 {
- sess.In("user_identity.id", classWithUserIdentityIdsTwo)
- }
-
- var m []*db.UserWithUserIdentity
- count, _ := sess.
- Join("LEFT", "user_identity", "user.id = user_identity.uid").
- Limit(req.Limit, (req.Page-1)*req.Limit).GroupBy("user.id").FindAndCount(&m)
- resp.Total = count
-
- var userIdentitiesMap = map[string][]db.UserIdentityWithClass{}
- for _, v := range m {
- userIdentityDb.Set(v.User.Id)
- userIdentities, err1 := userIdentityDb.FindUserIdentityWithClass()
- if err1 != nil {
- return resp, err1
- }
- for _, v1 := range *userIdentities {
- userIdentitiesMap[utils.IntToStr(v1.Uid)] = append(userIdentitiesMap[utils.IntToStr(v1.Uid)], v1)
- }
- }
- fmt.Println("!!!!!!!!!")
- for _, v := range m {
- temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
- Id: v.User.Id,
- IsTeacher: 0,
- }
- for _, v1 := range userIdentitiesMap[utils.IntToStr(v.User.Id)] {
- temp.Nickname = v1.User.Nickname
- temp.Phone = v1.User.Phone
- temp.Avatar = v1.User.Avatar
- temp.CreateAt = v1.User.CreateAt
- //TODO::判断是否为老师
- if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
- temp.UserIdentities = append(temp.UserIdentities, struct {
- Id int `json:"id" label:"身份id"`
- EnterpriseId int `json:"enterprise_id" label:"企业id"`
- IdNo string `json:"id_no" label:"身份证号"`
- CertType int `json:"cert_type" 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.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})
- temp.IsTeacher = 1
- }
- if v1.Identity == enum2.UserIdentityForCentralKitchenForStudent {
- temp.UserIdentities = append(temp.UserIdentities, struct {
- Id int `json:"id" label:"身份id"`
- EnterpriseId int `json:"enterprise_id" label:"企业id"`
- IdNo string `json:"id_no" label:"身份证号"`
- CertType int `json:"cert_type" 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.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})
- }
- }
- resp.List = append(resp.List, temp)
- }
- resp.UserIdentityKindList = []map[string]interface{}{
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForStudent),
- "value": enum2.UserIdentityForCentralKitchenForStudent,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForTeacher),
- "value": enum2.UserIdentityForCentralKitchenForTeacher,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForCentralKitchenForWorker),
- "value": enum2.UserIdentityForCentralKitchenForWorker,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForStudent),
- "value": enum2.UserIdentityForSelfSupportForStudent,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForTeacher),
- "value": enum2.UserIdentityForSelfSupportForTeacher,
- },
- {
- "name": enum2.UserIdentity.String(enum2.UserIdentityForSelfSupportForWorker),
- "value": enum2.UserIdentityForSelfSupportForWorker,
- },
- }
- resp.UserIdentityCertTypeList = []map[string]interface{}{
- {
- "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForIdCard),
- "value": enum2.UserIdentityCertTypeForIdCard,
- },
- {
- "name": enum2.UserIdentityCertType.String(enum2.UserIdentityCertTypeForStudentId),
- "value": enum2.UserIdentityCertTypeForStudentId,
- },
- //{
- // "name": enum.UserIdentityCertType.String(enum.UserIdentityCertTypeForPassport),
- // "value": enum.UserIdentityCertTypeForPassport,
- //},
- }
- return
- }
-
- func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByNursingHomeResp, err error) {
- //1、判断是否过滤 "教师"
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(0)
- userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId)
- if err != nil {
- return
- }
- var userIdentitiesMap = map[string][]model.UserIdentity{}
- var uids []int
- 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.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
- for _, v := range m {
- temp := md.EnterpriseUserListByNursingHomeStruct{
- Id: v.Id,
- Nickname: v.Nickname,
- Phone: v.Phone,
- Avatar: v.Avatar,
- CreateAt: v.CreateAt,
- }
- for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
- temp.UserIdentities = append(temp.UserIdentities, struct {
- Id int `json:"id" label:"身份id"`
- IdNo string `json:"id_no" label:"身份证号"`
- EnterpriseName string `json:"enterprise_name" label:"单位名"`
- Name string `json:"name" label:"姓名"`
- }{Id: v1.Id, IdNo: v1.IdNo, EnterpriseName: req.EnterpriseName, Name: v1.Name})
- }
- resp.List = append(resp.List, temp)
- }
- return
- }
|