Exemple #1
0
        /// <summary>
        /// 处理同步学生信息 学生信息同步6张表
        /// 分别为: School_Students,Sys_User,Sys_User_Role,Sys_UserLogOn,Dorm_DormStudent,Dorm_Dorm
        /// </summary>
        public void ProcessStudent()
        {
            Console.WriteLine("南航项目:开始同步学生信息 --> " + DateTime.Now.ToLocalTime());
            var sw = new Stopwatch();

            sw.Start();

            var newDb = new NHModel();
            var oldDb = new NanHangAccept();

            ///---------      Step1: 更新 School_Students 表数据      ---------///
            ProcessSchoolStudentInfo(oldDb, newDb);
            Console.WriteLine(" *** 同步 School_Students 结束 。");
            ///---------      Step2: 更新 Sys_User 表数据      ---------///
            ProcessSchoolStudentSysUser(oldDb, newDb);
            Console.WriteLine(" *** 同步 Sys_User 结束 。");
            ///---------      Step3: 更新 Sys_User_Role 表数据      ---------///
            ProcessSchoolStudentSysUserRole(oldDb, newDb);
            Console.WriteLine(" *** 同步 Sys_User_Role 结束 。");
            ///---------      Step4: 更新 Sys_UserLogOn 表数据      ---------///
            ProcessSchoolStudentSysUserLogOn(oldDb, newDb);
            Console.WriteLine(" *** 同步 Sys_UserLogOn 结束 。");
            ///---------      Step5: 更新 Dorm_Dorm 表数据      ---------///
            ProcessSchoolStudentDormInfo(oldDb, newDb);
            Console.WriteLine(" *** 同步 Dorm_Dorm 结束 。");
            ///---------      Step6: 更新 Dorm_DormStudent 表数据      ---------///
            ProcessSchoolStudentSysUserDormStudent(oldDb, newDb);
            Console.WriteLine(" *** 同步 Dorm_DormStudent 结束 。");

            //newDb.BulkDelete(newDb.StudentInfoes.ToList()); //批量删除中间表的所有数据
            newDb.Dispose();
            oldDb.Dispose();
            sw.Stop();
            Console.WriteLine("南航项目:同步学生信息结束 --> 合计耗时:" + sw.ElapsedMilliseconds / 1000 + "s");
        }
Exemple #2
0
        /// <summary>
        /// 处理同步学生信息 学生信息同步6张表
        /// 分别为: School_Students,Sys_User,Sys_User_Role,Sys_UserLogOn,Dorm_DormStudent,Dorm_Dorm
        /// </summary>
        public void ProcessStudent(EFContext db)
        {
            Console.WriteLine("南航项目:开始同步学生信息 --> " + DateTime.Now.ToLocalTime());
            var sw = new Stopwatch();

            sw.Start();
            var newDb = new NHModel();

            ///---------      Step1: 更新 School_Students 表数据      ---------///
            ProcessSchoolStudentInfo(db, newDb);
            Console.WriteLine(" *** 同步 School_Students 结束 。");
            ///---------      Step2: 更新 Sys_User 表数据      ---------///
            ProcessSchoolStudentSysUser(db, newDb);
            Console.WriteLine(" *** 同步 Sys_User 结束 。");
            ///---------      Step3: 更新 Dorm_Dorm 表数据      ---------///
            ProcessSchoolStudentDormInfo(db, newDb);
            Console.WriteLine(" *** 同步 宿舍相关的表 结束 。");
            ///---------      Step5: 更新 Dorm_Dorm 表数据      ---------///
            ProcessStudentSysUserRole(db, newDb);
            Console.WriteLine(" *** 同步 用户角色表 结束 。");
            //newDb.BulkDelete(newDb.StudentInfoes.ToList()); //批量删除中间表的所有数据
            newDb.Dispose();
            db.Dispose();
            sw.Stop();
            Console.WriteLine("南航项目:同步学生信息结束 --> 合计耗时:" + sw.ElapsedMilliseconds / 1000 + "s");
        }
Exemple #3
0
        /// <summary>
        /// 处理同步组织机构信息
        /// </summary>
        public void ProcessOrgInfo(EFContext db)
        {
            Console.WriteLine("开始同步教师组织机构信息: 南航项目 --> " + DateTime.Now.ToLocalTime());
            var sw = new Stopwatch();

            sw.Start();
            //校方数据集(分为两种:修改数据和新增数据)
            var newDb   = new NHModel();
            var newData = newDb.Set <Teacher_Organ>().AsNoTracking().Select(p => new OrganMoudle {
                Id = p.OrgId, Name = p.OrgName, ParentId = p.ParentOrgId, EnCode = p.OrgId
            }).ToList();
            //获取生产环境数据库数据集
            var oldData = db.Set <Org>().AsNoTracking().Select(p => new OrganMoudle {
                Id = p.Id, Name = p.Name, ParentId = p.ParentId, EnCode = p.Code
            }).ToList();
            var addList = newData.Except(oldData).ToList(); //取差集 (新增和修改数据)

            var idList  = oldData.Select(p => p.Id).ToList();
            var endList = new List <Org>();

            foreach (var org in addList)
            {
                if (org.ParentId == null)
                {
                    org.ParentId = "3";
                }
                if (idList.Contains(org.Id))
                {
                    db.Set <Org>().Where(p => p.Id.Equals(org.Id)).Update(p => new Org
                    {
                        ParentId = org.ParentId,
                        Name     = org.Name
                    });
                }
                else
                {
                    endList.Add(new Org()
                    {
                        Id       = org.Id,
                        Name     = org.Name,
                        ParentId = org.ParentId,
                        Code     = org.EnCode
                    });
                }
            }
            //newDb.BulkDelete(newDb.OrganizationInfoes.ToList()); //操作完成后,删除取出来的数据
            //oldDb.BulkInsert(endList);
            db.Set <Org>().AddRange(endList);
            db.SaveChanges();
            newDb.Dispose();
            sw.Stop();
            Console.WriteLine("南航项目:同步组织机构信息结束 --> 合计耗时:" + sw.ElapsedMilliseconds / 1000 + "s");
        }