|
- 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"`
- 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
- }
-
- 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)
- }
- 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{}
- userIdentityDb := db.UserIdentityDb{}
- 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("!!!!!!!!!")
- classWithUserDb := db.ClassWithUserDb{}
- classWithUserDb.Set()
- 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"`
- 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.UserIdentity.Id, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.UserIdentity.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0})
- temp.IsTeacher = 1
- }
- if v1.Identity == enum2.UserIdentityForCentralKitchenForStudent {
- 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.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})
- }
- }
- resp.List = append(resp.List, temp)
- }
- 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
- }
|