Example #1
0
        /// <summary>
        /// 修改学生手机号或联系人手机号,将手机号信息推送至家校互联账户
        /// <para>作     者:蔡亚康 </para>
        /// <para>创建时间: 2019-03-21 </para>
        /// </summary>
        /// <param name="rawStudent">原学生信息</param>
        /// <param name="newStudent">新学生信息</param>
        /// <param name="rawContacts">原学生联系人信息</param>
        /// <param name="newContacts">新学生联系人信息</param>
        private static void StudentPublish(TblCstStudent rawStudent, TblCstStudent newStudent, List <TblCstStudentContact> rawContacts, List <TblCstStudentContact> newContacts)
        {
            StudentPassportChangeInDto result = new StudentPassportChangeInDto();

            List <string> rawMobiles = new List <string>();   //原手机号
            List <string> newMobiles = new List <string>();   //新手机号


            //原手机号集合
            rawMobiles.Add(rawStudent.LinkMobile);
            rawMobiles.AddRange(rawContacts.Select(t => t.Mobile));
            rawMobiles = rawMobiles.Where(t => !string.IsNullOrEmpty(t))
                         .Distinct()
                         .ToList();


            //新手机号集合
            newMobiles.Add(newStudent.LinkMobile);
            newMobiles.AddRange(newContacts.Select(t => t.Mobile));
            newMobiles = newMobiles.Where(t => !string.IsNullOrEmpty(t))
                         .Distinct()
                         .ToList();


            result.MobileAddList    = newMobiles.Except(rawMobiles).ToList();
            result.MobileDeleteList = rawMobiles.Except(newMobiles).ToList();


            //获取手机号在在其他学生的账户列表
            TblCstStudentRepository        studentRepository = new TblCstStudentRepository();
            TblCstStudentContactRepository contactRepository = new TblCstStudentContactRepository();

            var studentList = studentRepository.SearchByMobiles(result.MobileDeleteList);
            var contactList = contactRepository.SearchByMobiles(result.MobileDeleteList);


            //被删除的号码,在studentList,contactList 还存在,说明还不允许删除
            List <string> existMobiles = new List <string>();

            existMobiles.AddRange(studentList.Select(t => t.LinkMobile));
            existMobiles.AddRange(contactList.Select(t => t.Mobile));
            existMobiles = existMobiles.Distinct().ToList();


            existMobiles.ForEach(item =>
            {
                result.MobileDeleteList.Remove(item);
            });

            // 推送至消息队列
            new StudentFamilyProducerService().Publish(result);
        }