using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using EMIS.Entities; using EMIS.ViewModel.UniversityManage.AdministrativeOrgan; using EMIS.ViewModel.UniversityManage.TeacherManage; using EMIS.DataLogic.Repositories; namespace EMIS.DataLogic.UniversityManage.AdministrativeOrgan { public class DepartmentDAL { public DepartmentRepository DepartmentRepository { get; set; } public DepartmentProfileRepository DepartmentProfileRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public CampusRepository CampusRepository { get; set; } public UniversityRepository UniversityRepository { get; set; } public StaffRepository StaffRepository { get; set; } public StaffProfileRepository StaffProfileRepository { get; set; } public UserRepository UserRepository { get; set; } /// /// 查询对应的部门信息View /// /// /// public IQueryable GetDepartmentViewQueryable(Expression> expDepartment) { var query = from dep in DepartmentRepository.GetList(expDepartment) join c in UserRepository.Entities on dep.CF_DepartmentProfile.DirectorID equals c.UserID into gu from guic in gu.DefaultIfEmpty() join d in UserRepository.Entities on dep.CF_DepartmentProfile.DeputyDirectorID equals d.UserID into gude from gudeic in gude.DefaultIfEmpty() join sta in ( from sta in StaffRepository.Entities group sta by sta.DepartmentID into stagr select new { DepartmentID = stagr.Key, StaffCount = stagr.Count() } ) on dep.DepartmentID equals sta.DepartmentID into tempsta from stadep in tempsta.DefaultIfEmpty() select new DepartmentView { DepartmentID = dep.DepartmentID, No = dep.No, Name = dep.Name, SimpleName = dep.SimpleName, EnglishName = dep.EnglishName, CampusID = dep.CF_College.CampusID, CampusNo = dep.CF_College.CF_Campus.No, CampusName = dep.CF_College.CF_Campus.Name, CollegeID = dep.CollegeID, CollegeCode = dep.CF_College.No, CollegeName = dep.CF_College.Name, HierarchyID = dep.HierarchyID, DirectorID = dep.CF_DepartmentProfile.DirectorID, DirectorName = guic.Name, DeputyDirectorID = dep.CF_DepartmentProfile.DeputyDirectorID, DeputyDirectorName = gudeic.Name, FoundDate = dep.CF_DepartmentProfile.FoundDate, StaffCount = stadep.StaffCount == null ? 0 : stadep.StaffCount, Remark = dep.Remark, RecordStatus = dep.RecordStatus, CreateUserID = dep.CreateUserID, CreateTime = dep.CreateTime, ModifyUserID = dep.ModifyUserID, ModifyTime = dep.ModifyTime }; return query; } /// /// 查询教研室对应的教师信息StaffView /// /// /// public IQueryable GetStaffViewQueryable(Expression> expDepartment) { var query = from dep in DepartmentRepository.GetList(expDepartment) join sf in StaffRepository.Entities on dep.DepartmentID equals sf.DepartmentID join pr in StaffProfileRepository.Entities on sf.UserID equals pr.UserID into temppr from sfpr in temppr.DefaultIfEmpty() join col in CollegeRepository.Entities on sf.CollegeID equals col.CollegeID into tempcol from sfcol in tempcol.DefaultIfEmpty() join us in UserRepository.Entities on sf.UserID equals us.UserID select new StaffView { UserID = sf.UserID, StaffCode = us.LoginID, Name = us.Name, UsedName = sfpr.UsedName, CampusID = sfcol.CampusID, CampusCode = sfcol.CF_Campus.No, CampusName = sfcol.CF_Campus.Name, CollegeID = sf.CollegeID, CollegeNo = sfcol.No, CollegeName = sfcol.Name, DepartmentID = sf.DepartmentID, DepartmentCode = dep.No, DepartmentName = dep.Name, Nationality = sfpr.Nationality, Place = sfpr.Place, SexID = sf.SexID, BirthDate = sf.BirthDate, NationID = sf.NationID, PoliticsID = sf.PoliticsID, CertificatesType = sf.CertificatesType, CertificatesNum = sf.CertificatesNum, TeacherTypeID = sf.TeacherTypeID, IncumbencyState = sf.IncumbencyState, SituationID = sf.SituationID, TitleID = sf.TitleID, LiteracyLevelID = sf.LiteracyLevelID, LearnPositionID = sf.LearnPositionID, IsDualTeacher = sf.IsDualTeacher ?? false, PaymentLevelID = sf.PaymentLevelID, WorkDate = sf.WorkDate, ComeSchoolDate = sf.ComeSchoolDate, Email = sfpr.Email, ZIPCode = sfpr.ZIPCode, WeChatNum = sfpr.WeChatNum, QQ = sfpr.QQ, Telephone = sfpr.Telephone, OfficeTelephone = sfpr.OfficeTelephone, HousePhone = sfpr.HousePhone, Mobile = sfpr.Mobile, Speciality = sfpr.Speciality, HealthStateID = sfpr.HealthStateID, ReligionID = sfpr.ReligionID, Account = sfpr.Account, Residence = sfpr.Residence, HomeAddress = sfpr.HomeAddress, Address = sfpr.Address, NowAddress = sfpr.NowAddress, PhotoUrl = sf.PhotoUrl, PhotoHasValue = (sf.PhotoUrl == null || sf.PhotoUrl == "") ? false : true, Profile = sf.Profile, Remark = sf.Remark, RecordStatus = sf.RecordStatus, CreateUserID = sf.CreateUserID, CreateTime = sf.CreateTime, ModifyUserID = sf.ModifyUserID, ModifyTime = sf.ModifyTime }; return query; } } }