using Edu.AOP.CustomerAttribute;
using Edu.Cache.User;
using Edu.Common;
using Edu.Common.Enum.EduTask;
using Edu.Common.Enum.User;
using Edu.Common.Plugin;
using Edu.Model.CacheModel;
using Edu.Model.Entity.EduTask;
using Edu.Model.ViewModel.BackClass;
using Edu.Model.ViewModel.Contract;
using Edu.Model.ViewModel.EduTask;
using Edu.Model.ViewModel.Exam;
using Edu.Model.ViewModel.Grade;
using Edu.Model.ViewModel.Sell;
using Edu.Model.ViewModel.User;
using Edu.Model.ViewModel.WeChat;
using Edu.Repository.BackClass;
using Edu.Repository.Contract;
using Edu.Repository.Course;
using Edu.Repository.EduTask;
using Edu.Repository.Exam;
using Edu.Repository.Grade;
using Edu.Repository.Sell;
using Edu.Repository.User;
using Edu.Repository.WeChat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VT.FW.DB;

namespace Edu.Module.EduTask
{
    /// <summary>
    /// 教务单据处理类
    /// </summary>
    public class EducationReceiptModule
    {
        /// <summary>
        /// 教务单据仓储层
        /// </summary>
        private readonly RB_Education_ReceiptRepository education_ReceiptRepository = new RB_Education_ReceiptRepository();

        /// <summary>
        /// 教务单据审核记录仓储层对象
        /// </summary>
        private readonly RB_Education_RecordRepository education_RecordRepository = new RB_Education_RecordRepository();

        /// <summary>
        /// 教务单据审核人员信息仓储层对象
        /// </summary>
        private readonly RB_Education_RelevanceRepository education_RelevanceRepository = new RB_Education_RelevanceRepository();

        /// <summary>
        /// 学员退课仓储层对象
        /// </summary>
        private readonly RB_Student_BackClassRepository student_BackClassRepository = new RB_Student_BackClassRepository();

        /// <summary>
        /// 学员停课仓储层对象
        /// </summary>
        private readonly RB_Student_StopClassRepository student_StopClassRepository = new RB_Student_StopClassRepository();

        /// <summary>
        /// 临时上课邀请计划仓储层对象
        /// </summary>
        private readonly RB_Student_TempInvitationRepository student_TempInvitationRepository = new RB_Student_TempInvitationRepository();
        /// <summary>
        /// 调课仓储层对象
        /// </summary>
        private readonly RB_Change_ClassPlanRepository change_ClassPlanRepository = new RB_Change_ClassPlanRepository();



        /// <summary>
        /// 学生请假仓储层对象
        /// </summary>
        private readonly RB_Student_LeaveRepository studentLeaveRepository = new RB_Student_LeaveRepository();

        /// <summary>
        /// 老师仓储层对象
        /// </summary>
        private readonly RB_TeacherRepository teacherRepository = new RB_TeacherRepository();

        /// <summary>
        /// 教室仓储层对象
        /// </summary>
        private readonly RB_Class_RoomRepository class_RoomRepository = new RB_Class_RoomRepository();

        /// <summary>
        /// 订单学员仓储层对象
        /// </summary>
        private readonly RB_Order_GuestRepository order_GuestRepository = new RB_Order_GuestRepository();

        /// <summary>
        /// 订单转班、拆分仓储层对象
        /// </summary>
        private readonly RB_Order_ChangeRepository order_ChangeRepository = new RB_Order_ChangeRepository();

        /// <summary>
        /// 转班订单
        /// </summary>
        private readonly OrderChangeModule orderChangeModule = new OrderChangeModule();

        /// <summary>
        /// 班级上课计划仓储层对象
        /// </summary>
        private readonly RB_Class_PlanRepository class_PlanRepository = new RB_Class_PlanRepository();

        /// <summary>
        /// 班级上课计划上课时间仓储层对象
        /// </summary>
        private readonly RB_Class_TimeRepository class_TimeRepository = new RB_Class_TimeRepository();

        /// <summary>
        /// 用户仓储层
        /// </summary>
        private readonly RB_AccountRepository accountRepository = new RB_AccountRepository();

        /// <summary>
        /// 试卷仓储层对象
        /// </summary>
        private readonly RB_Examination_PaperRepository examination_PaperRepository = new RB_Examination_PaperRepository();

        /// <summary>
        /// 考试发布仓储层对象
        /// </summary>
        private readonly RB_Examination_PublishRepository examination_PublishRepository = new RB_Examination_PublishRepository();

        /// <summary>
        /// 退课协议仓储层对象
        /// </summary>
        private readonly RB_BackClass_ProtocolRepository backClass_ProtocolRepository = new RB_BackClass_ProtocolRepository();

        /// <summary>
        /// 投稿信息
        /// </summary>
        private readonly RB_Contribute_InfoRepository contribute_InfoRepository = new RB_Contribute_InfoRepository();
        /// <summary>
        /// 素材
        /// </summary>
        private readonly RB_Contribute_MediumRepository contribute_MediumRepository = new RB_Contribute_MediumRepository();


        /// <summary>
        /// 获取教务单据分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<object> GetEducationReceiptPageModule(int pageIndex, int pageSize, out long rowsCount, EducationReceiptQuery query)
        {
            List<object> result = new List<object>();
            var list = education_ReceiptRepository.GetEducationReceiptPageRepository(pageIndex, pageSize, out rowsCount, query);
            if (list != null && list.Count > 0)
            {
                //退课详情
                List<RB_Student_BackClass_ViewModel> backClassLisit = new List<RB_Student_BackClass_ViewModel>();
                //退课协议列表
                List<RB_BackClass_Protocol_ViewModel> backClassProtocolList = new List<RB_BackClass_Protocol_ViewModel>();
                //调课申请
                List<RB_Change_ClassPlan_ViewModel> changeClassList = new List<RB_Change_ClassPlan_ViewModel>();
                //停课申请
                List<RB_Student_StopClass_ViewModel> stopClassList = new List<RB_Student_StopClass_ViewModel>();
                //临时上课邀请申请
                List<RB_Student_TempInvitation_ViewModel> studentTempInvitationClassList = new List<RB_Student_TempInvitation_ViewModel>();


                //学生请假申请
                List<RB_Student_Leave_ViewModel> studentLeaveList = new List<RB_Student_Leave_ViewModel>();

                List<RB_Order_Guest_ViewModel> orderGuestLeaveList = new List<RB_Order_Guest_ViewModel>();
                //班级上课计划-学生请假申请列表
                List<RB_Class_Plan_ViewModel> planLeaveList = new List<RB_Class_Plan_ViewModel>();
                //班级上课时间-学生请假申请列表
                List<RB_Class_Time_ViewModel> timeLeaveList = new List<RB_Class_Time_ViewModel>();


                //老师列表
                List<RB_Teacher_ViewModel> teacherList = new List<RB_Teacher_ViewModel>();
                //学生信息
                List<RB_Order_Guest_ViewModel> orderGuestList = new List<RB_Order_Guest_ViewModel>(); //学生信息
                List<RB_Order_Guest_ViewModel> orderGuestTempInvitationList = new List<RB_Order_Guest_ViewModel>();

                //教室列表
                List<RB_Class_Room_ViewModel> roomList = new List<RB_Class_Room_ViewModel>();
                //班级上课计划列表
                List<RB_Class_Plan_ViewModel> planList = new List<RB_Class_Plan_ViewModel>();
                //班级上课时间列表
                List<RB_Class_Time_ViewModel> timeList = new List<RB_Class_Time_ViewModel>();
                //订单转班列表
                List<RB_Order_Change_ViewModel> orderTransList = new List<RB_Order_Change_ViewModel>();

                ///试卷列表（组卷审核）
                List<RB_Examination_Paper_ViewModel> ExaminationPaperList = new List<RB_Examination_Paper_ViewModel>();
                //考试申请列表（考试申请审核）
                List<RB_Examination_Publish_ViewModel> ExaminationPublishList = new List<RB_Examination_Publish_ViewModel>();
                var groupList = list.GroupBy(qitem => new { qitem.ReceiptType }).Select(qitem => new { qitem.Key.ReceiptType });
                string Ids = string.Join(",", list.Select(qitem => qitem.Id));
                var recordList = education_RecordRepository.GetEducationRecordListRepository(new RB_Education_Record_ViewModel()
                {
                    QConditionIds = Ids,
                    AuditStatus = EduTaskRrocessStatus.AuditIng
                });
                //投稿详情
                List<RB_Contribute_Info_ViewModel> contributeList = new List<RB_Contribute_Info_ViewModel>();
                foreach (var subItem in groupList)
                {
                    #region 退课申请
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.BackClass)
                    {
                        string backIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        backClassLisit = student_BackClassRepository.GetStudentBackClassListRepository(new RB_Student_BackClass_ViewModel()
                        {
                            QBackIds = backIds
                        });
                        backClassProtocolList = backClass_ProtocolRepository.GetBackClassProtocolListRepository(new RB_BackClass_Protocol_ViewModel()
                        {
                            QBackIds = backIds
                        });
                        if (backClassLisit != null && backClassLisit.Count > 0)
                        {
                            foreach (var item in backClassLisit)
                            {
                                var protocolModel = backClassProtocolList?.Where(qitem => qitem.BackId == item.BackId)?.FirstOrDefault();
                                item.BackClassProtocolId = protocolModel?.Id ?? 0;
                                item.ProtocolNum = protocolModel?.ProtocolNum ?? "";
                            }
                        }
                    }
                    #endregion

                    #region 调课申请
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ChangeClass)
                    {
                        string changeIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        changeClassList = change_ClassPlanRepository.GetChangeClassPlanListRepository(new RB_Change_ClassPlan_ViewModel()
                        {
                            Q_Change_ClassPlan_Ids = changeIds
                        });
                        List<int> teacherIds = new List<int>();
                        List<int> classRoomIds = new List<int>();
                        if (changeClassList != null && changeClassList.Count > 0)
                        {
                            foreach (var tempModel in changeClassList)
                            {
                                if (tempModel != null)
                                {
                                    if (!string.IsNullOrEmpty(tempModel.SourceData))
                                    {
                                        tempModel.OldChangePlanItemList = Common.Plugin.JsonHelper.DeserializeObject<List<ChangePlanItem>>(tempModel.SourceData);
                                        if (tempModel.OldChangePlanItemList != null && tempModel.OldChangePlanItemList.Count > 0)
                                        {
                                            var tempTeacherIds = Common.ConvertHelper.StringToList(string.Join(",", tempModel.OldChangePlanItemList.Select(qitem => qitem.TeacherId)));
                                            if (tempTeacherIds != null && tempTeacherIds.Count > 0)
                                            {
                                                teacherIds.AddRange(tempTeacherIds);
                                            }
                                            var tempClassRoomIds = Common.ConvertHelper.StringToList(string.Join(",", tempModel.OldChangePlanItemList.Select(qitem => qitem.ClassRoomId)));
                                            if (tempClassRoomIds != null && tempClassRoomIds.Count > 0)
                                            {
                                                classRoomIds.AddRange(tempClassRoomIds);
                                            }
                                        }
                                    }
                                    if (!string.IsNullOrEmpty(tempModel.TargetData))
                                    {
                                        if (tempModel.MoveType == 1)
                                        {
                                            tempModel.NewChangePlanItemList = Common.Plugin.JsonHelper.DeserializeObject<List<ChangePlanItem>>(tempModel.TargetData);
                                            if (tempModel.NewChangePlanItemList != null && tempModel.NewChangePlanItemList.Count > 0)
                                            {
                                                var tempNTeacherIds = Common.ConvertHelper.StringToList(string.Join(",", tempModel.NewChangePlanItemList.Select(qitem => qitem.TeacherId)));
                                                if (tempNTeacherIds != null && tempNTeacherIds.Count > 0)
                                                {
                                                    teacherIds.AddRange(tempNTeacherIds);
                                                }
                                                var tempNClassRoomIds = Common.ConvertHelper.StringToList(string.Join(",", tempModel.NewChangePlanItemList.Select(qitem => qitem.ClassRoomId)));
                                                if (tempNClassRoomIds != null && tempNClassRoomIds.Count > 0)
                                                {
                                                    classRoomIds.AddRange(tempNClassRoomIds);
                                                }
                                            }
                                        }
                                        else if (tempModel.MoveType == 2)
                                        {
                                            tempModel.AllChangePlanModel = Common.Plugin.JsonHelper.DeserializeObject<AllChangePlanItem>(tempModel.TargetData);
                                            if (tempModel.AllChangePlanModel != null && tempModel.AllChangePlanModel.TeacherId > 0)
                                            {
                                                teacherIds.Add(tempModel.AllChangePlanModel.TeacherId);
                                            }
                                            if (tempModel.AllChangePlanModel != null && tempModel.AllChangePlanModel.ClassRoomId > 0)
                                            {
                                                classRoomIds.Add(tempModel.AllChangePlanModel.ClassRoomId);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (teacherIds != null && teacherIds.Count > 0)
                        {
                            teacherList = teacherRepository.GetTeacherListRepository(new Model.ViewModel.User.RB_Teacher_ViewModel()
                            {
                                QTIds = string.Join(",", teacherIds)
                            });
                        }
                        if (classRoomIds != null && classRoomIds.Count > 0)
                        {
                            roomList = class_RoomRepository.GetClassRoomListRepository(new RB_Class_Room_ViewModel()
                            {
                                QRoomIds = string.Join(",", classRoomIds)
                            });
                        }
                    }
                    #endregion

                    #region 停课申请

                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.StopClass)
                    {
                        string changeIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        stopClassList = student_StopClassRepository.GetStudentStopClassListRepository(new RB_Student_StopClass_ViewModel()
                        {
                            Q_Student_StopClass_Ids = changeIds,
                            IsAuditThrough = -1
                        });
                        if (stopClassList != null && stopClassList.Any())
                        {
                            string orderGuestIds = string.Join(",", stopClassList.Select(x => x.OrderGuestId));
                            orderGuestList = order_GuestRepository.GetStopingStudentPage(new RB_Order_Guest_ViewModel
                            {
                                OrderGuestIds = orderGuestIds
                            });
                            if (orderGuestList != null && orderGuestList.Any())
                            {
                                orderGuestList.ForEach(x => x.EnterName = x.EnterID > 0 ? (UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "") : "");
                                stopClassList.ForEach(x => x.Order_Guest_ViewModel = orderGuestList.Where(y => y.Id == x.OrderGuestId).FirstOrDefault());
                            }
                        }
                    }

                    #endregion

                    #region 临时上课邀请申请
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.InvitationClass)
                    {
                        string changeIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        studentTempInvitationClassList = student_TempInvitationRepository.GetStundetTempInvitationListRepository(new RB_Student_TempInvitation_ViewModel()
                        {
                            Q_TempInvitation_Ids = changeIds,
                        });
                        if (studentTempInvitationClassList != null && studentTempInvitationClassList.Any())
                        {
                            string orderGuestIds = string.Join(",", studentTempInvitationClassList.Select(x => x.OrderGuestIds));
                            if (!string.IsNullOrWhiteSpace(orderGuestIds))
                            {
                                orderGuestTempInvitationList = order_GuestRepository.GetStopingStudentPage(new RB_Order_Guest_ViewModel
                                {
                                    OrderGuestIds = orderGuestIds
                                });
                                if (orderGuestTempInvitationList != null && orderGuestTempInvitationList.Any())
                                {
                                    orderGuestTempInvitationList.ForEach(x => x.EnterName = x.EnterID > 0 ? (UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "") : "");
                                }
                            }

                            string classTimeIds = string.Join(",", studentTempInvitationClassList.Select(x => x.ClassTimeIds));
                            if (!string.IsNullOrWhiteSpace(classTimeIds))
                            {
                                timeList = class_TimeRepository.GetClassTimeListRepository(new RB_Class_Time_ViewModel { QClassTimeIds = classTimeIds });
                                if (timeList != null && timeList.Any())
                                {
                                    string classPlanIds = string.Join(",", timeList.Select(x => x.ClassPlanId));

                                    if (!string.IsNullOrWhiteSpace(classPlanIds))
                                    {
                                        planList = class_PlanRepository.GetClassPlanListRepository(new RB_Class_Plan_ViewModel { QClassPlanIds = classPlanIds });
                                    }
                                }

                            }

                        }

                    }

                    #endregion

                    #region 订单转班
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.OrderTransClass)
                    {
                        string transClassIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        var tempList = order_ChangeRepository.GetOrderChangeListRepository(new RB_Order_Change_ViewModel()
                        {
                            QIds = transClassIds,
                            ChangeType = 1,
                        });
                        if (tempList != null && tempList.Count > 0)
                        {
                            orderTransList.AddRange(tempList);
                        }
                    }
                    #endregion

                    #region 订单分拆
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.OrderSplitClass)
                    {
                        string transClassIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        var tempList = order_ChangeRepository.GetOrderChangeListRepository(new RB_Order_Change_ViewModel()
                        {
                            QIds = transClassIds,
                            ChangeType = 2,
                        });
                        if (tempList != null && tempList.Count > 0)
                        {
                            orderTransList.AddRange(tempList);
                        }
                    }
                    #endregion

                    #region 学生请假申请
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.LeaveClass)
                    {
                        string changeIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        studentLeaveList = studentLeaveRepository.GetStudentLeaveListRepository(new RB_Student_Leave_ViewModel()
                        {
                            Q_Student_Leave_Ids = changeIds,
                        });
                        if (studentLeaveList != null && studentLeaveList.Any())
                        {
                            string orderGuestIds = string.Join(",", studentLeaveList.Select(x => x.OrderGuestId));
                            if (!string.IsNullOrWhiteSpace(orderGuestIds))
                            {
                                orderGuestLeaveList = order_GuestRepository.GetStopingStudentPage(new RB_Order_Guest_ViewModel
                                {
                                    OrderGuestIds = orderGuestIds
                                });
                            }

                            string classTimeIds = string.Join(",", studentLeaveList.Select(x => x.ClassTimeIds));
                            if (!string.IsNullOrWhiteSpace(classTimeIds))
                            {
                                timeLeaveList = class_TimeRepository.GetClassTimeListRepository(new RB_Class_Time_ViewModel { QClassTimeIds = classTimeIds });
                                if (timeLeaveList != null && timeLeaveList.Any())
                                {
                                    string classPlanIds = string.Join(",", timeLeaveList.Select(x => x.ClassPlanId));

                                    if (!string.IsNullOrWhiteSpace(classPlanIds))
                                    {
                                        planLeaveList = class_PlanRepository.GetClassPlanListRepository(new RB_Class_Plan_ViewModel { QClassPlanIds = classPlanIds });
                                    }
                                }
                            }

                        }

                    }
                    #endregion


                    #region 组卷审批
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ZuJuan)
                    {
                        string transClassIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        ExaminationPaperList = examination_PaperRepository.GetExaminationPaperListRepository(new RB_Examination_Paper_ViewModel()
                        {
                            QPaperIds = transClassIds
                        });
                    }
                    #endregion

                    #region 考试申请
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ExamApply)
                    {
                        string transClassIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        ExaminationPublishList = examination_PublishRepository.GetExaminationPublishListRepository(new RB_Examination_Publish_ViewModel()
                        {
                            QPublishIds = transClassIds
                        });
                    }
                    #endregion

                    #region 投稿审核
                    if (subItem.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.Contribute)
                    {
                        string transClassIds = string.Join(",", list.Where(qitem => qitem.ReceiptType == subItem.ReceiptType).Select(qitem => qitem.RelationId));
                        contributeList = contribute_InfoRepository.GetList(new RB_Contribute_Info_ViewModel()
                        {
                            Q_ContributeIds = transClassIds
                        });
                        if (contributeList.Any())
                        {
                            List<int> MeadiumIds = new List<int>();
                            if (contributeList.Where(x => x.CoverImageId > 0).Any())
                            {
                                MeadiumIds.AddRange(contributeList.Where(x => x.CoverImageId > 0).Select(x => x.CoverImageId).Distinct());
                            }
                            if (contributeList.Where(x => x.VideoMediumId > 0).Any())
                            {
                                MeadiumIds.AddRange(contributeList.Where(x => x.VideoMediumId > 0).Select(x => x.VideoMediumId).Distinct());
                            }
                            if (contributeList.Where(x => !string.IsNullOrEmpty(x.ImageMediumIds)).Any())
                            {
                                foreach (var item in contributeList.Where(x => !string.IsNullOrEmpty(x.ImageMediumIds)))
                                {
                                    MeadiumIds.AddRange(JsonHelper.DeserializeObject<List<int>>("[" + item.ImageMediumIds + "]"));
                                }
                            }
                            List<RB_Contribute_Medium_ViewModel> mediumList = new List<RB_Contribute_Medium_ViewModel>();
                            if (MeadiumIds.Any())
                            {
                                mediumList = contribute_MediumRepository.GetList(new RB_Contribute_Medium_ViewModel() { Group_Id = query.Group_Id, MediumIds = string.Join(",", MeadiumIds.Distinct()) });
                            }

                            foreach (var item in contributeList)
                            {
                                if (item.CoverImageId > 0)
                                {
                                    item.CoverImagePath = mediumList.Where(x => x.Id == item.CoverImageId).FirstOrDefault()?.ImageUrl ?? "";
                                }
                                if (item.VideoMediumId > 0)
                                {
                                    var mediumModel = mediumList.Where(x => x.Id == item.VideoMediumId).FirstOrDefault();
                                    item.VideoMediumPath = mediumModel?.Path ?? "";
                                    if (item.Type == Common.Enum.WeChat.ContributeInfoTypeEnum.Video)
                                    {
                                        item.VideoCoverImage = mediumModel?.VideoWXImage ?? "";
                                    }
                                }
                                item.ImageList = new List<RB_Contribute_Medium_ViewModel>();
                                if (!string.IsNullOrEmpty(item.ImageMediumIds))
                                {
                                    item.ImageList = mediumList.Where(x => ("," + item.ImageMediumIds + ",").Contains("," + x.Id + ",")).ToList();
                                }
                            }
                        }
                    }
                    #endregion
                }

                foreach (var item in list)
                {
                    object DataObj = new object();
                    //退课
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.BackClass)
                    {
                        DataObj = backClassLisit?.Where(qitem => qitem.BackId == item.RelationId)?.FirstOrDefault();
                    }
                    //调课
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ChangeClass)
                    {
                        var tempModel = changeClassList.Where(qitem => qitem.Id == item.RelationId)?.FirstOrDefault();
                        if (tempModel.OldChangePlanItemList != null && tempModel.OldChangePlanItemList.Count > 0)
                        {
                            foreach (var sItem in tempModel.OldChangePlanItemList)
                            {
                                sItem.TeacherName = teacherList?.Where(qitem => qitem.TId == sItem.TeacherId)?.FirstOrDefault()?.TeacherName ?? "";
                                sItem.ClassRoomName = roomList?.Where(qitem => qitem.RoomId == sItem.ClassRoomId)?.FirstOrDefault()?.RoomName ?? "";
                            }
                        }
                        if (tempModel.NewChangePlanItemList != null && tempModel.NewChangePlanItemList.Count > 0)
                        {
                            foreach (var sItem in tempModel.NewChangePlanItemList)
                            {
                                sItem.TeacherName = teacherList?.Where(qitem => qitem.TId == sItem.TeacherId)?.FirstOrDefault()?.TeacherName ?? "";
                                sItem.ClassRoomName = roomList?.Where(qitem => qitem.RoomId == sItem.ClassRoomId)?.FirstOrDefault()?.RoomName ?? "";
                            }
                        }
                        if (tempModel.AllChangePlanModel != null)
                        {
                            tempModel.AllChangePlanModel.TeacherName = teacherList?.Where(qitem => qitem.TId == tempModel.AllChangePlanModel.TeacherId)?.FirstOrDefault()?.TeacherName ?? "";
                            tempModel.AllChangePlanModel.ClassRoomName = roomList?.Where(qitem => qitem.RoomId == tempModel.AllChangePlanModel.ClassRoomId)?.FirstOrDefault()?.RoomName ?? "";
                        }
                        DataObj = tempModel;
                    }
                    //停课
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.StopClass)
                    {
                        DataObj = stopClassList?.Where(qitem => qitem.Id == item.RelationId)?.FirstOrDefault();
                    }
                    //临时上课邀请
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.InvitationClass)
                    {
                        var tempModel = studentTempInvitationClassList.Where(qitem => qitem.Id == item.RelationId)?.FirstOrDefault();
                        tempModel.ClassPlanTimeList = new List<ClassPlanTime>();
                        foreach (var itemClassTimeIds in tempModel.ClassTimeIds.Split(","))
                        {
                            if (!string.IsNullOrWhiteSpace(itemClassTimeIds))
                            {
                                var tempTimeModel = timeList.Where(x => x.ClassTimeId.ToString() == itemClassTimeIds).FirstOrDefault();
                                ClassPlanTime classPlanTimeModel = new ClassPlanTime()
                                {
                                    StartTime = tempTimeModel?.StartTime ?? "",
                                    EndTime = tempTimeModel?.EndTime ?? "",
                                    TimeHour = tempTimeModel?.TimeHour ?? 0
                                };
                                classPlanTimeModel.ClassDate = planList.Where(x => x.ClassPlanId == tempTimeModel.ClassPlanId).FirstOrDefault()?.ClassDate.ToString("yyyy-MM-dd") ?? "";
                                tempModel.ClassPlanTimeList.Add(classPlanTimeModel);
                            }
                        }
                        tempModel.OrderGuestList = new List<RB_Order_Guest_ViewModel>();
                        foreach (var itemOrderGuestIds in tempModel.OrderGuestIds.Split(","))
                        {
                            if (!string.IsNullOrWhiteSpace(itemOrderGuestIds))
                            {
                                tempModel.OrderGuestList.AddRange(orderGuestTempInvitationList.Where(x => x.Id.ToString() == itemOrderGuestIds));
                            }
                        }

                        DataObj = tempModel;

                    }
                    //订单转班
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.OrderTransClass)
                    {
                        DataObj = orderTransList?.Where(qitem => qitem.Id == item.RelationId && qitem.ChangeType == 1)?.FirstOrDefault();
                    }
                    //订单分拆
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.OrderSplitClass)
                    {
                        DataObj = orderTransList?.Where(qitem => qitem.Id == item.RelationId && qitem.ChangeType == 2)?.FirstOrDefault();
                    }
                    //学生请假申请
                    string accountName = "";
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.LeaveClass)
                    {
                        var tempModel = studentLeaveList.Where(qitem => qitem.Id == item.RelationId)?.FirstOrDefault();
                        tempModel.LeaveInfoList = new List<LeaveInfoModel>();
                        foreach (var itemClassTimeIds in tempModel.ClassTimeIds.Split(","))
                        {
                            if (!string.IsNullOrWhiteSpace(itemClassTimeIds))
                            {
                                var tempTimeModel = timeLeaveList.Where(x => x.ClassTimeId.ToString() == itemClassTimeIds).FirstOrDefault();
                                LeaveInfoModel classPlanTimeModel = new LeaveInfoModel()
                                {
                                    StartTime = tempTimeModel?.StartTime ?? "",
                                    EndTime = tempTimeModel?.EndTime ?? "",
                                    TimeHour = tempTimeModel?.TimeHour ?? 0,
                                    ClassPlanId = tempTimeModel.ClassPlanId,
                                    ClassTimeId = tempTimeModel.ClassTimeId,
                                    TeacherName = planLeaveList.Where(x => x.ClassPlanId == tempTimeModel.ClassPlanId).FirstOrDefault()?.TeacherName ?? "",
                                    RoomName = planLeaveList.Where(x => x.ClassPlanId == tempTimeModel.ClassPlanId).FirstOrDefault()?.RoomName ?? "",
                                };
                                classPlanTimeModel.ClassDate = planLeaveList.Where(x => x.ClassPlanId == tempTimeModel.ClassPlanId).FirstOrDefault()?.ClassDate.ToString("yyyy-MM-dd") ?? "";
                                tempModel.LeaveInfoList.Add(classPlanTimeModel);
                            }
                        }
                        tempModel.Order_Guest_ViewModel = new RB_Order_Guest_ViewModel();
                        tempModel.Order_Guest_ViewModel = orderGuestLeaveList.Where(x => x.Id == tempModel.OrderGuestId).FirstOrDefault();
                        DataObj = tempModel;
                        accountName = tempModel.Order_Guest_ViewModel.GuestName;
                    }

                    //组卷
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ZuJuan)
                    {
                        DataObj = ExaminationPaperList?.Where(qitem => qitem.PaperId == item.RelationId)?.FirstOrDefault();
                    }
                    //考试发布
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ExamApply)
                    {
                        DataObj = ExaminationPublishList?.Where(qitem => qitem.Id == item.RelationId)?.FirstOrDefault();
                    }
                    //投稿审批
                    if (item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.Contribute)
                    {
                        var touGao= contributeList?.Where(x => x.Id == item.RelationId)?.FirstOrDefault();
                        if (touGao != null)
                        {
                            touGao.Content = "";
                            touGao.SendContent = "";
                        }
                        DataObj = touGao;
                    }
                    object AuditObj = new object();
                    if (item.VerifyStatus == EduTaskRrocessStatus.NotAudit || item.VerifyStatus == EduTaskRrocessStatus.AuditIng)
                    {
                        var tempRecordList = recordList?.Where(qitem => qitem.ConditionId == item.Id)?.ToList();
                        if (tempRecordList != null && tempRecordList.Count > 0)
                        {
                            foreach (var rItem in tempRecordList)
                            {
                                rItem.AuditManName = UserReidsCache.GetUserLoginInfo(rItem.AuditEmId)?.AccountName ?? "";
                            }
                            AuditObj = new
                            {
                                tempRecordList[0].AuditNode,
                                AuditManList = tempRecordList.Select(qitem => new { qitem.AuditEmId, qitem.AuditManName })
                            };
                        }
                    }
                    var obj = new
                    {
                        item.Id,
                        item.Title,
                        item.ClassId,
                        item.ClassName,
                        item.ClassNo,
                        item.OrderId,
                        item.ReceiptType,
                        DataObj,
                        item.SpecialNode,
                        item.RelationId,
                        ReceiptTypeName = item.ReceiptType.ToName(),
                        CreateByName = item.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.LeaveClass ? accountName : UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName,
                        CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                        item.TeacherName,
                        item.SchoolName,
                        item.CourseName,
                        AuditObj,
                        item.VerifyStatus,
                        AuditStatusName = item.VerifyStatus == Common.Enum.EduTask.EduTaskRrocessStatus.NotAudit ? "待审" : item.VerifyStatus.ToName(),
                        ReceiptFileList = string.IsNullOrWhiteSpace(item.ReceiptFile) ? new List<string>() : Common.Plugin.JsonHelper.DeserializeObject<List<string>>(item.ReceiptFile)
                    };
                    result.Add(obj);
                }
            }
            return result;
        }

        /// <summary>
        ///  获取单据当前审核人列表
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public virtual object GetCurrentAuditManModule(int Id)
        {
            List<object> list = new List<object>();
            var recordList = education_RecordRepository.GetEducationRecordListRepository(new RB_Education_Record_ViewModel()
            {
                QConditionIds = Id.ToString(),
                AuditStatus = EduTaskRrocessStatus.AuditIng
            });
            if (recordList != null && recordList.Count > 0)
            {
                foreach (var item in recordList)
                {
                    var obj = new
                    {
                        item.Id,
                        item.ConditionId,
                        item.AuditId,
                        item.AuditEmId,
                        item.NewAuditEmId
                    };
                    list.Add(obj);
                }
            }
            return list;
        }

        /// <summary>
        /// 作废教务单据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [TransactionCallHandler]
        public bool InvalidReceiptModule(int Id)
        {
            bool flag = false;
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Education_Receipt_ViewModel.VerifyStatus),(int)Edu.Common.Enum.User.WFRrocessStatus.Invalid}
            };
            flag = education_ReceiptRepository.Update(fileds, new WhereHelper(nameof(RB_Education_Receipt_ViewModel.Id), Id));
            if (flag)
            {
                var model = education_ReceiptRepository.GetEntity(Id);
                if (model != null && model.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.StopClass)
                {
                    student_StopClassRepository.UpdateStudentStopClass(model.Id, 4);
                }
                if (model != null && model.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ZuJuan)
                {
                    Dictionary<string, object> filedsZuJuan = new Dictionary<string, object>()
                    {
                        {nameof(RB_Examination_Paper_ViewModel.ExamineStatus),(int)EduTaskRrocessStatus.Invalid}
                    };
                    flag = education_ReceiptRepository.Update(filedsZuJuan, new WhereHelper(nameof(RB_Examination_Paper_ViewModel.PaperId), model.RelationId));
                }
                if (model != null && model.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ExamApply)
                {
                    Dictionary<string, object> filedsZuJuan = new Dictionary<string, object>()
                    {
                        {nameof(RB_Examination_Publish_ViewModel.ExamineStatus),(int)EduTaskRrocessStatus.Invalid}
                    };
                    flag = examination_PublishRepository.Update(filedsZuJuan, new WhereHelper(nameof(RB_Examination_Publish_ViewModel.Id), model.RelationId));
                }
                if (model != null && model.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.Contribute) {
                    Dictionary<string, object> fileds1 = new Dictionary<string, object>()
                    {
                        {nameof(RB_Contribute_Info_ViewModel.AuditState),(int)Common.Enum.WeChat.ContributeInfoStateEnum.Reject}
                    };
                    flag = contribute_InfoRepository.Update(fileds1, new WhereHelper(nameof(RB_Contribute_Info_ViewModel.Id), model.RelationId));
                }
            }
            return flag;
        }

        /// <summary>
        /// 修改审核人员
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool EditAuditManModule(List<RB_Education_Record_ViewModel> list)
        {
            bool flag = true;
            foreach (var item in list)
            {
                if (flag && item.NewAuditEmId > 0)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Education_Record_ViewModel.AuditEmId),item.NewAuditEmId }
                    };
                    flag = education_RecordRepository.Update(fileds, new WhereHelper(nameof(RB_Education_Record_ViewModel.Id), item.Id));
                }
            }
            if (flag)
            {
                var recordList = education_RecordRepository.GetEducationRecordListRepository(new RB_Education_Record_ViewModel()
                {
                    AuditId = list[0].AuditId
                });
                var relevance = education_RelevanceRepository.GetEducationRelevanceListRepository(new RB_Education_Relevance_ViewModel()
                {
                    ConditionId = list[0].ConditionId,

                })?.FirstOrDefault();

                if (recordList != null && recordList.Count > 0 && relevance != null)
                {
                    string audits = string.Join(",", recordList.Select(qitem => qitem.AuditEmId));
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Education_Relevance_ViewModel.ToAuditId),audits.TrimStart(',').TrimEnd(',') }
                    };
                    flag = education_RelevanceRepository.Update(fileds, new WhereHelper(nameof(RB_Education_Relevance_ViewModel.Id), relevance.Id));
                }
            }
            return flag;
        }

        /// <summary>
        /// 获取单据详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public object GetEducationReceiptInfoModule(object Id)
        {
            var obj = new List<object>();
            var receipt = education_ReceiptRepository.GetEntity(Id);
            string ApplyReason = "";
            if (receipt.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.BackClass)
            {
                //获取单据实体类
                var backModel = student_BackClassRepository.GetEntity(receipt.RelationId);
                ApplyReason = backModel?.ApplyReason ?? "";
            }
            else if (receipt.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ChangeClass)
            {
                var changeClassModel = change_ClassPlanRepository.GetEntity<RB_Change_ClassPlan_ViewModel>(receipt.RelationId);
                ApplyReason = changeClassModel?.Remarks ?? "";
            }
            else if (receipt.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.StopClass)
            {
                var changeClassModel = student_StopClassRepository.GetEntity<RB_Student_StopClass_ViewModel>(receipt.RelationId);
                ApplyReason = changeClassModel?.Remarks ?? "";
            }
            else if (receipt.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.LeaveClass)
            {
                var studentLeaveModel = studentLeaveRepository.GetEntity<RB_Student_Leave_ViewModel>(receipt.RelationId);
                ApplyReason = studentLeaveModel?.Remarks ?? "";
            }
            //获取审核记录
            var aurList = education_RecordRepository.GetEducationRecordListRepository(new RB_Education_Record_ViewModel()
            {
                ConditionId = receipt.Id,
            });
            //审核关联列表
            var arList = education_RelevanceRepository.GetEducationRelevanceListRepository(new RB_Education_Relevance_ViewModel()
            {
                ConditionId = receipt.Id
            });

            obj.Add(new
            {
                NodeName = "制单人",
                AduitStatus = 2,
                AuditWayName = "",
                AduitStatusName = "发起",
                SubList = new List<object>()
                {
                   new{
                         AduitName= UserReidsCache.GetUserLoginInfo(receipt.CreateBy)?.AccountName ?? "",
                         Description=ApplyReason,
                         CreateTime=Common.ConvertHelper.FormatTime(receipt.CreateTime),
                         AuditStatus=WFRrocessStatus.AuditThrough,
                         AuditStatusName = WFRrocessStatus.AuditThrough.ToName(),
                      }
                }
            });

            var existsList = arList.Where(qitem => aurList.Any(oldItem => qitem.Id == oldItem.AuditId));
            foreach (var item in existsList)
            {
                obj.Add(new
                {
                    NodeName = item.AuditDescription,
                    AduitStatus = item.Stauts,
                    AduitStatusName = GetWFRrocessStatusStrModule(item.Stauts),
                    AuditWayName = item.AuditWay != WFTAuditWayEnum.Successively ? item.AuditWay.ToName() : "",
                    SubList = aurList.Where(qitem => qitem.AuditId == item.Id).Select(qitem => new
                    {
                        AduitName = UserReidsCache.GetUserLoginInfo(qitem.AuditEmId)?.AccountName ?? "",
                        Description = !string.IsNullOrEmpty(qitem.Description) ? qitem.Description : "无",
                        CreateTime = Common.ConvertHelper.FormatTime(qitem.UpdateTime),
                        qitem.AuditStatus,
                        AuditStatusName = GetWFRrocessStatusStrModule(qitem.AuditStatus),
                    })
                });
            }
            return obj;
        }

        /// <summary>
        /// 教务单据审核
        /// </summary>
        /// <param name="model">审核信息</param>
        /// <param name="user">登录用户信息</param>
        /// <param name="message">返回提示信息</param>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool AduitEducationReceiptModule(EduReceiptAudit auditModel, UserInfo user, out string message)
        {
            message = "";
            bool flag = false;
            //获取单据实体类
            var receipt = education_ReceiptRepository.GetEntity(auditModel.Id);
            if (receipt == null)
            {
                message = "单据不存在,请核实!";
                return flag;
            }
            //抄送人
            string newRecipientIds = "";
            if (!string.IsNullOrEmpty(auditModel.RecipientIds))
            {
                newRecipientIds = ((!string.IsNullOrEmpty(receipt.RecipientIds) ? receipt.RecipientIds : "") + "," + auditModel.RecipientIds).TrimStart(',').TrimEnd(',');

                #region 抄送通知
                var notifyUsers = accountRepository.GetAccountListExtRepository(new RB_Account_ViewModel()
                {
                    QIds = newRecipientIds
                });
                if (notifyUsers != null && notifyUsers.Count() > 0)
                {
                    notifyUsers.ForEach(x =>
                    {
                        if (!string.IsNullOrEmpty(x.WorkUserId))
                        {
                            var recipientPath = HttpUtility.UrlEncode($"/teacher/change-class-manager?tab=4&id={receipt.Id}");
                            var content = $"<font color='info'>抄送通知</font> 你收到了一张{EnumHelper.ToName(receipt.ReceiptType)}单据抄送\n>**概要信息** \n>抄  送  人：<font color='comment'>{user.AccountName}</font>\n>单据编号：<font color='comment'>{receipt.Id}</font>\n>创  建  人：<font color='comment'>{UserReidsCache.GetUserLoginInfo(receipt.CreateBy).AccountName}</font>\n>申请时间：<font color='comment'>{receipt.CreateTime.ToString("MM-dd HH:mm")}</font>\n>请点击：[查看详情]({Config.ErpUrl}/autologin?loginId={x.Id}&target={recipientPath})";
                            PushWorkChatHelper.PushToWorkChat(content, x.WorkUserId, "抄送通知");
                        }
                    });
                }
                #endregion
            }
            //获取审核记录
            var aurList = education_RecordRepository.GetEducationRecordListRepository(new RB_Education_Record_ViewModel()
            {
                ConditionId = auditModel.Id,
            }); 
             //审核关联列表
             var arList = education_RelevanceRepository.GetEducationRelevanceListRepository(new RB_Education_Relevance_ViewModel()
            {
                ConditionId = auditModel.Id
            });

            //驳回处理
            if (auditModel.AuditStatus == 3)
            {
                //找出当前审核
                int Notcount = arList.Where(x => x.Stauts == EduTaskRrocessStatus.AuditNotThrough).Count();
                if (Notcount > 0)
                {
                    message = "该申请单已被拒绝!";
                    return false;
                }
                var ToAuditFlow = arList.Where(x => x.Stauts == EduTaskRrocessStatus.AuditIng).OrderBy(x => x.Sort).ToList();
                if (ToAuditFlow.Count <= 0)
                {
                    message = "该申请单审核已经完结!";
                    return false;
                }
                if (ToAuditFlow.Count > 0)
                {
                    var model = ToAuditFlow[0];
                    var RecordList = aurList.Where(x => x.AuditId == model.Id).ToList();
                    var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                    if (amodel == null)
                    {
                        message = "尚未匹配到审核相关信息，请联系管理员!";
                        return false;
                    }
                    //同时  修改  审核记录状态 审核流程 
                    model.Stauts = EduTaskRrocessStatus.AuditNotThrough;
                    if (!string.IsNullOrWhiteSpace(model.AuditedId))
                    {
                        model.AuditedId += "," + user.Id;
                    }
                    else
                    {
                        model.AuditedId = user.Id.ToString();
                    }

                    #region 更新审核记录表状态
                    flag = UpdateEduRecordModule(WFRrocessStatus.AuditNotThrough, auditModel.Description, user.Id, amodel.Id);

                    if (flag)
                    {
                        #region 驳回通知
                        var notifyUsers = accountRepository.GetWorkUserIdRepository(receipt.CreateBy);
                        if (!string.IsNullOrEmpty(notifyUsers))
                        {
                            var recipientPath = HttpUtility.UrlEncode($"/teacher/change-class-manager?tab=1&id={receipt.Id}");
                            var content = $"`业务单据驳回` 你有一张业务单据被驳回\n>**概要信息** \n>审  批  人：<font color='warning'>{user.AccountName}</font>\n>单据信息：<font color='comment'>{EnumHelper.ToName(receipt.ReceiptType)}单据 ({receipt.Id})</font>\n>驳回时间：<font color='comment'>{DateTime.Now.ToString("MM-dd HH-mm")}</font>\n>驳回理由：<font color='comment'>{auditModel.Description}</font>\n>请点击：[查看详情]({Config.ErpUrl}/autologin?loginId={receipt.CreateBy}&target={recipientPath})";
                            PushWorkChatHelper.PushToWorkChat(content, notifyUsers, "业务单据驳回通知");
                        }
                        #endregion
                    }

                    #endregion

                    #region 更新审核关联表状态
                    flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);
                    #endregion

                    var list = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).ToList();
                    int AuditCount = list.Count();
                    if (AuditCount > 0)//表示最后一个人就是子集审核   申请单 通过
                    {
                        foreach (var item in list)
                        {
                            flag = UpdateEduRecordModule(WFRrocessStatus.OtherHaveAudit, auditModel.Description, user.Id, item.Id);
                        }
                    }
                }

                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Education_Receipt_ViewModel.VerifyStatus),(int)EduTaskRrocessStatus.Rejected}
                };
                flag = education_ReceiptRepository.Update(fileds, new WhereHelper(nameof(RB_Education_Receipt_ViewModel.Id), receipt.Id));
                flag = UpdateOtherModule(receipt, auditModel, user);


            }
            //审核通过
            else
            {
                //找出当前审核
                int Notcount = arList.Where(x => x.Stauts == EduTaskRrocessStatus.AuditNotThrough).Count();
                if (Notcount > 0)
                {
                    message = "该申请单已被拒绝";
                    return false;
                }

                var ToAuditFlow = arList.Where(x => x.Stauts == EduTaskRrocessStatus.AuditIng).OrderBy(x => x.Sort).ToList();
                if (ToAuditFlow.Count <= 0)
                {
                    message = "该申请单审核已经完结";
                    return false;
                }
                //审核关联表字段
                var relevanceFileds = new Dictionary<string, object>();
                ///目前审核为最后一步
                if (ToAuditFlow.Count == 1)
                {
                    var model = ToAuditFlow[0];
                    var RecordList = aurList.Where(x => x.AuditId == model.Id).ToList();
                    if (model.AuditWay == WFTAuditWayEnum.Countersign)
                    {
                        //会签  所有人必须审核完该流程才算完成
                        var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                        if (amodel == null)
                        {
                            message = "尚未匹配到审核相关信息，请联系管理员!";
                            return false;
                        }

                        #region 更新审核记录表状态
                        flag = UpdateEduRecordModule(WFRrocessStatus.AuditThrough, auditModel.Description, user.Id, amodel.Id);
                        #endregion

                        int AuditCount = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).Count();
                        if (AuditCount <= 0)//表示最后一个人就是子集审核   申请单 通过
                        {
                            //同时  修改  审核记录状态 审核流程 
                            model.Stauts = EduTaskRrocessStatus.AuditThrough;
                            if (!string.IsNullOrWhiteSpace(model.AuditedId))
                            {
                                model.AuditedId += "," + user.Id;
                            }
                            else
                            {
                                model.AuditedId = user.Id.ToString();
                            }

                            #region 更新审核关联表状态
                            flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);
                            #endregion

                            flag = UpdateOtherModule(receipt, auditModel, user);

                        }
                        else
                        {
                            //同时  修改  审核记录状态 审核流程 
                            model.Stauts = EduTaskRrocessStatus.AuditThrough;
                            if (!string.IsNullOrWhiteSpace(model.AuditedId))
                            {
                                model.AuditedId += "," + user.Id;
                            }
                            else
                            {
                                model.AuditedId = user.Id.ToString();
                            }

                            #region 更新审核关联表状态
                            flag = UpdateEduRelevanceModule(model.Id, null, model.AuditedId);
                            #endregion
                        }
                    }
                    else if (model.AuditWay == WFTAuditWayEnum.OrSign)
                    {
                        var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                        if (amodel == null)
                        {
                            message = "尚未匹配到审核相关信息，请联系管理员!";
                            return false;
                        }
                        //同时  修改  审核记录状态 审核流程 
                        model.Stauts = EduTaskRrocessStatus.AuditThrough;
                        if (!string.IsNullOrWhiteSpace(model.AuditedId))
                        {
                            model.AuditedId += "," + user.Id;
                        }
                        else
                        {
                            model.AuditedId = user.Id.ToString();
                        }

                        #region 更新审核记录表状态
                        flag = UpdateEduRecordModule(WFRrocessStatus.AuditThrough, auditModel.Description, user.Id, amodel.Id);
                        #endregion

                        #region 更新审核关联表状态
                        flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);
                        #endregion

                        var list = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).ToList();
                        int AuditCount = list.Count();
                        if (AuditCount > 0)//表示最后一个人就是子集审核   申请单 通过
                        {
                            foreach (var item in list)
                            {
                                flag = UpdateEduRecordModule(WFRrocessStatus.OtherHaveAudit, auditModel.Description, user.Id, item.Id);
                            }
                        }
                        flag = UpdateOtherModule(receipt, auditModel, user);
                    }
                    else
                    {
                        var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                        if (amodel == null)
                        {
                            message = "尚未匹配到审核相关信息，请联系管理员!";
                            return false;
                        }
                        var list = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).ToList();
                        int AuditCount = list.Count();
                        if (AuditCount > 0)
                        {
                            message = "流程配置出错啦！非会签，或签 都只能有一个审核人!";
                            return false;
                        }
                        //同时  修改  审核记录状态 审核流程 
                        model.Stauts = EduTaskRrocessStatus.AuditThrough;
                        if (!string.IsNullOrWhiteSpace(model.AuditedId))
                        {
                            model.AuditedId += "," + user.Id;
                        }
                        else
                        {
                            model.AuditedId = user.Id.ToString();
                        }
                        #region 更新审核记录表状态
                        flag = UpdateEduRecordModule(WFRrocessStatus.AuditThrough, auditModel.Description, user.Id, amodel.Id);
                        #endregion
                        #region 更新审核关联表状态
                        flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);
                        #endregion

                        flag = UpdateOtherModule(receipt, auditModel, user);
                    }

                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Education_Receipt_ViewModel.VerifyStatus),(int)EduTaskRrocessStatus.AuditThrough}
                    };
                    flag = education_ReceiptRepository.Update(fileds, new WhereHelper(nameof(RB_Education_Receipt_ViewModel.Id), receipt.Id));
                    #region 完成通知
                    var notifyUsers = accountRepository.GetWorkUserIdRepository(receipt.CreateBy);
                    if (!string.IsNullOrEmpty(notifyUsers))
                    {
                        var recipientPath = HttpUtility.UrlEncode($"/teacher/change-class-manager?tab=1&id={receipt.Id}");
                        var content = $"<font color='info'>审核完成通知</font> 你有一张业务单据已审核完成\n>**概要信息** \n>审  批  人：<font color='warning'>{user.AccountName}</font>\n>单据信息：<font color='comment'>{EnumHelper.ToName(receipt.ReceiptType)}单据 ({receipt.Id})</font>\n>驳回时间：<font color='comment'>{DateTime.Now.ToString("MM-dd HH-mm")}</font>\n>审批备注：<font color='info'>已完成</font>\n>请点击：[查看详情]({Config.ErpUrl}/autologin?loginId={receipt.CreateBy}&target={recipientPath})";
                        PushWorkChatHelper.PushToWorkChat(content, notifyUsers, "业务单据驳回通知");
                    }
                    #endregion
                }
                //同时创建下一步审核  复制审核人到审核关联表   创建审核记录表
                else
                {
                    var model = ToAuditFlow[0];
                    var RecordList = aurList.Where(x => x.AuditId == model.Id).ToList();

                    //会签  所有人必须审核完该流程才算完成
                    if (model.AuditWay == WFTAuditWayEnum.Countersign)
                    {
                        var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                        if (amodel == null)
                        {
                            message = "尚未匹配到审核相关信息，请联系管理员!";
                            return false;
                        }
                        //审核记录状态
                        #region 更新审核记录表状态

                        flag = UpdateEduRecordModule(WFRrocessStatus.AuditThrough, auditModel.Description, user.Id, amodel.Id);
                        #endregion

                        int AuditCount = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).Count();
                        if (AuditCount <= 0)//表示最后一个人就是子集审核   申请单 通过
                        {
                            //同时  修改  审核流程 
                            model.Stauts = EduTaskRrocessStatus.AuditThrough;
                            if (!string.IsNullOrWhiteSpace(model.AuditedId))
                            {
                                model.AuditedId += "," + user.Id;
                            }
                            else
                            {
                                model.AuditedId = user.Id.ToString();
                            }
                            #region 更新审核关联表状态
                            flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);
                            #endregion
                            //赋值下一步到审核记录中  并更新这一步的待审核人
                            var modelNext = ToAuditFlow[1];
                            flag = InsertAuditRelevanceNext(receipt, modelNext);
                            if (flag == false)
                            {
                                message = "审核流程不完整无法审核，请联系相关负责人!";
                                return false;
                            }
                        }
                        else
                        {
                            //同时  修改  审核流程 
                            if (!string.IsNullOrWhiteSpace(model.AuditedId))
                            {
                                model.AuditedId += "," + user.Id;
                            }
                            else
                            {
                                model.AuditedId = user.Id.ToString();
                            }
                            #region 更新审核关联表状态
                            relevanceFileds = new Dictionary<string, object>
                            {
                                { nameof(RB_Education_Relevance_ViewModel.AuditedId), model.AuditedId },
                            };
                            flag = education_RelevanceRepository.Update(relevanceFileds, new WhereHelper(nameof(RB_Education_Relevance_ViewModel.Id), model.Id));
                            #endregion
                        }
                    }
                    else if (model.AuditWay == WFTAuditWayEnum.OrSign)
                    {
                        var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                        if (amodel == null)
                        {
                            message = "尚未匹配到审核相关信息，请联系管理员!";
                            return false;
                        }
                        //同时  修改  审核记录状态 审核流程 
                        model.Stauts = EduTaskRrocessStatus.AuditThrough;
                        if (!string.IsNullOrWhiteSpace(model.AuditedId))
                        {
                            model.AuditedId += "," + user.Id;
                        }
                        else
                        {
                            model.AuditedId = user.Id.ToString();
                        }
                        #region 更新审核记录表状态

                        flag = UpdateEduRecordModule(WFRrocessStatus.AuditThrough, auditModel.Description, user.Id, amodel.Id);
                        #endregion

                        #region 更新审核关联表状态
                        flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);
                        #endregion

                        var list = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).ToList();
                        int AuditCount = list.Count();
                        if (AuditCount > 0)//表示最后一个人就是子集审核   申请单 通过
                        {
                            foreach (var item in list)
                            {
                                flag = UpdateEduRecordModule(WFRrocessStatus.OtherHaveAudit, auditModel.Description, user.Id, item.Id);
                            }
                        }
                        //赋值下一步到审核记录中  并更新这一步的待审核人
                        var modelNext = ToAuditFlow[1];
                        flag = InsertAuditRelevanceNext(receipt, modelNext);
                        if (flag == false)
                        {
                            message = "审核流程不完整无法审核，请联系相关负责人!";
                            return false;
                        }
                    }
                    else
                    {
                        var amodel = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId == user.Id).FirstOrDefault();
                        if (amodel == null)
                        {
                            message = "尚未匹配到审核相关信息，请联系管理员!";
                            return false;
                        }
                        var list = RecordList.Where(x => x.AuditStatus == EduTaskRrocessStatus.AuditIng && x.AuditEmId != user.Id).ToList();
                        int AuditCount = list.Count();
                        if (AuditCount > 0)
                        {
                            message = "流程配置出错啦！非会签、或签 都只能有一个审核人!";
                            return false;
                        }
                        //同时  修改  审核记录状态 审核流程 
                        model.Stauts = EduTaskRrocessStatus.AuditThrough;
                        if (!string.IsNullOrWhiteSpace(model.AuditedId))
                        {
                            model.AuditedId += "," + user.Id;
                        }
                        else
                        {
                            model.AuditedId = user.Id.ToString();
                        }
                        #region 更新审核记录表状态
                        flag = UpdateEduRecordModule(WFRrocessStatus.AuditThrough, auditModel.Description, user.Id, amodel.Id);
                        #endregion

                        #region 更新审核关联表状态
                        flag = UpdateEduRelevanceModule(model.Id, model.Stauts, model.AuditedId);

                        #endregion
                        //赋值下一步到审核记录中  并更新这一步的待审核人
                        var modelNext = ToAuditFlow[1];
                        flag = InsertAuditRelevanceNext(receipt, modelNext);
                        if (flag == false)
                        {
                            message = "审核流程不完整无法审核，请联系相关负责人!";
                            return false;
                        }
                    }

                    #region 通过通知
                    var notifyUsers = accountRepository.GetWorkUserIdRepository(receipt.CreateBy);
                    if (!string.IsNullOrEmpty(notifyUsers))
                    {
                        var recipientPath = HttpUtility.UrlEncode($"/teacher/change-class-manager?tab=1&id={receipt.Id}");
                        var content = $"<font color='info'>审核通知</font> 你有一张业务单据被通过\n>**概要信息** \n>审  批  人：<font color='warning'>{user.AccountName}</font>\n>单据信息：<font color='comment'>{EnumHelper.ToName(receipt.ReceiptType)}单据 ({receipt.Id})</font>\n>驳回时间：<font color='comment'>{DateTime.Now.ToString("MM-dd HH-mm")}</font>\n>审批备注：<font color='warning'>进行中</font>\n>请点击：[查看详情]({Config.ErpUrl}/autologin?loginId={receipt.CreateBy}&target={recipientPath})";
                        PushWorkChatHelper.PushToWorkChat(content, notifyUsers, "业务单据驳回通知");
                    }
                    #endregion

                    #region 稿酬状态

                    if (receipt.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.Contribute && auditModel.SpecialNode == 1)
                    {
                        if (auditModel.AuditStatus == 2)
                        {
                            Dictionary<string, object> fileds1 = new Dictionary<string, object>()
                            {
                                {nameof(RB_Contribute_Info_ViewModel.RemunerationState),auditModel.RemunerationState}
                            };

                            flag = contribute_InfoRepository.Update(fileds1, new WhereHelper(nameof(RB_Contribute_Info_ViewModel.Id), receipt.RelationId));
                        }
                    }
                    #endregion

                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Education_Receipt_ViewModel.VerifyStatus),(int)EduTaskRrocessStatus.AuditIng}
                    };
                    flag = education_ReceiptRepository.Update(fileds, new WhereHelper(nameof(RB_Education_Receipt_ViewModel.Id), receipt.Id));
                }
            }
            return flag;
        }

        /// <summary>
        /// 获取审核状态字符串
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        private string GetWFRrocessStatusStrModule(EduTaskRrocessStatus status)
        {
            var statusName = "待审";
            switch (status)
            {
                case EduTaskRrocessStatus.AuditNotThrough: statusName = "拒绝"; break;
                case EduTaskRrocessStatus.AuditThrough: statusName = "通过"; break;
                case EduTaskRrocessStatus.NotAudit: statusName = "待审"; break;
                case EduTaskRrocessStatus.OtherHaveAudit: statusName = "通过"; break;
                case EduTaskRrocessStatus.Rejected: statusName = "驳回"; break;
                case EduTaskRrocessStatus.Invalid: statusName = "作废"; break;
            }
            return statusName;
        }

        /// <summary>
        /// 更新其他信息
        /// </summary>
        /// <param name="receiptModel">单据实体</param>
        /// <param name="auditModel">审核实体</param>
        /// <returns></returns>
        public bool UpdateOtherModule(RB_Education_Receipt receiptModel, EduReceiptAudit auditModel, UserInfo user)
        {
            bool flag = true;
            //退课
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.BackClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    flag = student_BackClassRepository.UpdateStudentBackClassRepository(receiptModel, auditModel);
                }
                if (auditModel.AuditStatus == 3)
                {
                    flag = student_BackClassRepository.UpdateStudentBackClassRepository(receiptModel, auditModel);
                }
            }
            //调课
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ChangeClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    flag = change_ClassPlanRepository.UpdateChangeClassPlan(receiptModel.Id);
                }
            }
            //停课
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.StopClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    flag = student_StopClassRepository.UpdateStudentStopClass(receiptModel.Id, auditModel.AuditStatus);
                }
                if (auditModel.AuditStatus == 3)
                {
                    flag = student_StopClassRepository.UpdateStudentStopClass(receiptModel.Id, auditModel.AuditStatus);
                }
            }
            //临时上课邀请
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.InvitationClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    flag = student_TempInvitationRepository.UpdateStundetTempInvitation(receiptModel.Id);

                }
            }
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.OrderTransClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    orderChangeModule.GetChangeOrderListModule();
                }
                else if (auditModel.AuditStatus == 3)
                {
                    student_BackClassRepository.UpdateGuestStateRepository(receiptModel, auditModel);
                }
            }
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.OrderSplitClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    orderChangeModule.UpdateOrderSplitModule(receiptModel);
                }
                else if (auditModel.AuditStatus == 3)
                {
                    //student_BackClassRepository.UpdateGuestStateRepository(receiptModel, auditModel);
                }
            }
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.LeaveClass)
            {
                if (auditModel.AuditStatus == 2)
                {
                    studentLeaveRepository.UpdateStundetLeave(receiptModel.Id, user.Id);
                }
            }
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ZuJuan)
            {
                if (auditModel.AuditStatus == 2)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Examination_Paper_ViewModel.ExamineStatus),(int)EduTaskRrocessStatus.AuditThrough}
                    };
                    flag = examination_PaperRepository.Update(fileds, new WhereHelper(nameof(RB_Examination_Paper_ViewModel.PaperId), receiptModel.RelationId));

                }
                if (auditModel.AuditStatus == 3)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Examination_Paper_ViewModel.ExamineStatus),(int)EduTaskRrocessStatus.Rejected},
                        {nameof(RB_Examination_Paper_ViewModel.ExamineRemark),auditModel.Description},
                    };
                    flag = examination_PaperRepository.Update(fileds, new WhereHelper(nameof(RB_Examination_Paper_ViewModel.PaperId), receiptModel.RelationId));
                }
            }
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.ExamApply)
            {
                if (auditModel.AuditStatus == 2)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Examination_Publish_ViewModel.ExamineStatus),(int)EduTaskRrocessStatus.AuditThrough}
                    };
                    flag = examination_PublishRepository.Update(fileds, new WhereHelper(nameof(RB_Examination_Publish_ViewModel.Id), receiptModel.RelationId));

                }
                if (auditModel.AuditStatus == 3)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Examination_Publish_ViewModel.ExamineStatus),(int)EduTaskRrocessStatus.Rejected}
                    };
                    flag = examination_PublishRepository.Update(fileds, new WhereHelper(nameof(RB_Examination_Publish_ViewModel.Id), receiptModel.RelationId));

                }
            }
            if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.Contribute)
            {
                if (auditModel.AuditStatus == 2)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Contribute_Info_ViewModel.AuditState),(int)Common.Enum.WeChat.ContributeInfoStateEnum.Audited},
                        {nameof(RB_Contribute_Info_ViewModel.PublishDate), DateTime.Now}
                    };
                    if (auditModel.SpecialNode == 1)
                    {
                        fileds.Add(nameof(RB_Contribute_Info_ViewModel.RemunerationState), auditModel.RemunerationState);
                    }
                    flag = contribute_InfoRepository.Update(fileds, new WhereHelper(nameof(RB_Contribute_Info_ViewModel.Id), receiptModel.RelationId));
                }
                if (auditModel.AuditStatus == 3)
                {
                    Dictionary<string, object> fileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Contribute_Info_ViewModel.AuditState),(int)Common.Enum.WeChat.ContributeInfoStateEnum.Reject}
                    };
                    flag = contribute_InfoRepository.Update(fileds, new WhereHelper(nameof(RB_Contribute_Info_ViewModel.Id), receiptModel.RelationId));
                }
            }

            return flag;
        }


        /// <summary>
        /// 更新审核记录表信息
        /// </summary>
        /// <param name="wFRrocessStatus">审核状态</param>
        /// <param name="Description">审核意见</param>
        /// <param name="UserId">审核人Id</param>
        /// <param name="Id">审核记录编号</param>
        /// <returns></returns>
        private bool UpdateEduRecordModule(WFRrocessStatus wFRrocessStatus, string Description, int UserId, int Id)
        {
            var recordFileds = new Dictionary<string, object>
            {
                { nameof(RB_Education_Record_ViewModel.AuditStatus), wFRrocessStatus },
                { nameof(RB_Education_Record_ViewModel.Description),Description} ,
                { nameof(RB_Education_Record_ViewModel.UpdateBy),UserId},
                { nameof(RB_Education_Record_ViewModel.UpdateTime),DateTime.Now}
            };
            bool flag = education_RecordRepository.Update(recordFileds, new WhereHelper(nameof(RB_Education_Record_ViewModel.Id), Id));
            return flag;
        }

        /// <summary>
        /// 更新审核流程信息
        /// </summary>
        /// <param name="status"></param>
        /// <param name="AuditedId"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        private bool UpdateEduRelevanceModule(int Id, EduTaskRrocessStatus? status = null, string AuditedId = "")
        {
            var relevanceFileds = new Dictionary<string, object>();
            if (!string.IsNullOrEmpty(AuditedId))
            {
                relevanceFileds.Add(nameof(RB_Education_Relevance_ViewModel.AuditedId), AuditedId);
            }
            if (status != null)
            {
                relevanceFileds.Add(nameof(RB_Education_Relevance_ViewModel.Stauts), status);
            }
            bool flag = education_RelevanceRepository.Update(relevanceFileds, new WhereHelper(nameof(RB_Education_Relevance_ViewModel.Id), Id));
            return flag;
        }

        /// <summary>
        /// 添加拷贝审核节点
        /// </summary>
        /// <param name="receiptModel">单据实体</param>
        /// <param name="modelNext">审核关联</param>
        private bool InsertAuditRelevanceNext(RB_Education_Receipt receiptModel, RB_Education_Relevance_ViewModel modelNext)
        {
            if (modelNext != null)
            {
                RB_Education_Relevance_ViewModel auditRelevance = modelNext.RefMapperTo<RB_Education_Relevance_ViewModel>();
                if (auditRelevance != null)
                {
                    List<int> empList = new List<int>();
                    if (auditRelevance.AuditType == WFTAuditTypeEnum.SpecifiedMember)
                    {
                        //添加指定用户
                        if (!string.IsNullOrEmpty(auditRelevance.UserIds))
                        {
                            var userList = Common.ConvertHelper.StringToList(auditRelevance.UserIds);
                            foreach (var item in userList)
                            {
                                if (item > 0)
                                {
                                    empList.Add(item);
                                }
                            }
                        }
                    }
                    else if (auditRelevance.AuditType == WFTAuditTypeEnum.Role)
                    {
                        //添加角色对应的人员
                        if (!string.IsNullOrEmpty(auditRelevance.PostIds))
                        {
                            var postList = Common.ConvertHelper.StringToList(auditRelevance.PostIds);
                            if (postList != null && postList.Count > 0)
                            {
                                foreach (var item in postList)
                                {
                                    //本班教师审核
                                    if (item == 1)
                                    {
                                        var teacherId = education_ReceiptRepository.GetTeacherIdRepository(receiptModel.ClassId);
                                        if (teacherId > 0)
                                        {
                                            empList.Add(teacherId);
                                        }
                                    }
                                    //关联销售审核
                                    else if (item == 2)
                                    {
                                        var saleId = education_ReceiptRepository.GetOrderSaleIdRepository(receiptModel.OrderId);
                                        empList.Add(saleId);
                                    }
                                    //分区校长审核
                                    else if (item == 3)
                                    {
                                        var schoolMasterId = education_ReceiptRepository.GetSchoolMasterIdRepository(receiptModel.Group_Id);
                                        if (schoolMasterId > 0)
                                        {
                                            empList.Add(schoolMasterId);
                                        }
                                    }
                                    //教务长审核
                                    else if (item == 4)
                                    {
                                        var schoolJiaoWuZhangId = education_ReceiptRepository.GetSchoolJiaoWuZhangIdRepository(receiptModel.Group_Id);
                                        if (schoolJiaoWuZhangId > 0)
                                        {
                                            empList.Add(schoolJiaoWuZhangId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (auditRelevance.AuditType == WFTAuditTypeEnum.Post)
                    {
                        var postUserIdList = education_ReceiptRepository.GetPostIdsRepository(receiptModel.Group_Id, auditRelevance.SysPostIds);
                        if (postUserIdList != null && postUserIdList.Count > 0)
                        {
                            empList.AddRange(postUserIdList);
                        }
                    }
                    InsertBatcheAuditRecord(empList, receiptModel.Id, auditRelevance);
                    #region 下一步审批通知
                    var notifyUsers = accountRepository.GetAccountListExtRepository(new RB_Account_ViewModel()
                    {
                        QIds = string.Join(",", empList)
                    });
                    if (notifyUsers != null && notifyUsers.Count() > 0)
                    {
                        notifyUsers.ForEach(x =>
                        {
                            if (!string.IsNullOrEmpty(x.WorkUserId))
                            {
                                var recipientPath = HttpUtility.UrlEncode($"/teacher/change-class-manager?tab=3&id={receiptModel.Id}");
                                string AccountName = "";
                                if (receiptModel.ReceiptType == Common.Enum.Finance.ReceiptTypeEnum.LeaveClass)
                                {

                                    AccountName = studentLeaveRepository.GetStudentLeaveListRepository(new RB_Student_Leave_ViewModel()
                                    {
                                        Q_Student_Leave_Ids = receiptModel.RelationId.ToString(),
                                    }).FirstOrDefault()?.Order_Guest_ViewModel?.GuestName ?? "";
                                }
                                else
                                {
                                    AccountName = UserReidsCache.GetUserLoginInfo(receiptModel.CreateBy)?.AccountName;
                                }

                                var content = $"待审通知 你有一张业务单据等待审核\n>**概要信息** \n>单据信息：<font color='comment'>{EnumHelper.ToName(receiptModel.ReceiptType)}单据 ({receiptModel.Id})</font>\n>创  建  人：<font color='comment'>{AccountName}</font>\n>创建时间：<font color='comment'>{receiptModel.CreateTime.ToString("MM-dd HH-mm")}</font>\n>请点击：[查看详情]({Config.ErpUrl}/autologin?loginId={x.Id}&target={recipientPath})";
                                PushWorkChatHelper.PushToWorkChat(content, x.WorkUserId, "业务单据待审通知");
                            }
                        });
                    }
                    #endregion
                }
            }
            return true;
        }

        /// <summary>
        /// 批量添加审核人
        /// </summary>
        /// <param name="empIds">审核人id集合</param>
        /// <param name="wfId">工作流id</param>
        /// <param name="auditRelevance">审核节点</param>
        private void InsertBatcheAuditRecord(List<int> empIds, int wfId, RB_Education_Relevance_ViewModel auditRelevance)
        {
            List<RB_Education_Record_ViewModel> auditrecordList = new List<RB_Education_Record_ViewModel>();
            foreach (var item in empIds)
            {
                RB_Education_Record_ViewModel auditrecord = new RB_Education_Record_ViewModel
                {
                    AuditEmId = item,
                    AuditId = auditRelevance.Id,
                    AuditStatus = EduTaskRrocessStatus.AuditIng,
                    CreateBy = item,
                    CreateTime = DateTime.Now,
                    UpdateBy = item,
                    UpdateTime = DateTime.Now,
                    ConditionId = wfId,
                    Description = "",
                };
                auditrecordList.Add(auditrecord);
            }
            education_RecordRepository.InsertBatch(auditrecordList);

            auditRelevance.ToAuditId = string.Join(",", empIds);
            education_RelevanceRepository.Update(auditRelevance);
        }


        /// <summary>
        /// 获取教务单据列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Education_Receipt_ViewModel> GetEducationReceiptListModule(EducationReceiptQuery query)
        {
            return education_ReceiptRepository.GetEducationReceiptListRepository(query);
        }
    }
}
