123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Transactions;
- using EMIS.CommonLogic.Specialtyclass;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.CommonLogic.SystemSetting;
- using EMIS.DataLogic.DataCenterSynch;
- using EMIS.DataLogic.SystemSetting;
- using EMIS.Entities;
- using EMIS.ViewModel;
- namespace EMIS.CommonLogic.DataCenterSynch
- {
- public class FacultySynchServices : FacultymajorServices, IFacultySynchServices
- {
- public Lazy<IParameterServices> ParameterServices { get; set; }
- public DictionaryItemDAL DictionaryItemDAL { get; set; }
- public FacultySynchDAL FacultySynchDAL { get; set; }
- public void Synchr()
- {
- var lastSynchTime = ParameterServices.Value.GetParameterValue<DateTime>(CF_ParameterType.SynchFacultyLastTime);
- var nowTime = DateTime.Now;
- var allFacultyList = FacultySynchDAL.XXBZ_JWXT_ZYXX_VIEWRepository.GetList(x => x.TIMESTAMPS >= lastSynchTime || lastSynchTime == null).ToList();
- var allFacultyCodeList = allFacultyList.Select(x => x.USER_DM.Trim()).Distinct().ToList();
- var allCollegeNoList = allFacultyList.Select(x => x.SSYXB_USERDM.Trim()).Distinct().ToList();
- var dbFacultyList = this.FacultymajorDAL.FacultymajorRepository.GetList(x => allFacultyCodeList.Contains(x.Code)).ToList();
- var dbCollegeList = this.FacultymajorDAL.CollegeRepository.GetList(x => allCollegeNoList.Contains(x.No)).ToList();
- var standardDictionaryCode = typeof(CF_Standard).Name;
- var dbDictionaryList = this.DictionaryItemDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == standardDictionaryCode && allFacultyCodeList.Contains(x.Code)).ToList();
- var insertDictionaryList = (
- from all in allFacultyList
- from db in dbDictionaryList.Where(x => x.Code == all.USER_DM.Trim()).DefaultIfEmpty()
- where db == null
- select new Sys_DictionaryItem
- {
- DictionaryItemID = Guid.NewGuid(),
- DictionaryCode = standardDictionaryCode,
- Code = all.USER_DM.Trim(),
- Name = all.ZWMC.Trim(),
- Value = Convert.ToInt32(all.USER_DM.Trim()),
- RecordStatus = (int)SYS_STATUS.USABLE,
- OrderNo = Convert.ToInt16(all.USER_DM.Trim()),
- IsEditable = true
- }
- ).ToList();
- var updateDictionaryList = (
- from all in allFacultyList
- from db in dbDictionaryList.Where(x => x.Code == all.USER_DM.Trim())
- select new Sys_DictionaryItem
- {
- DictionaryItemID = db.DictionaryItemID,
- DictionaryCode = db.DictionaryCode,
- Code = all.USER_DM.Trim(),
- Name = all.ZWMC.Trim(),
- Value = Convert.ToInt32(all.USER_DM.Trim()),
- RecordStatus = db.RecordStatus,
- OrderNo = Convert.ToInt16(all.USER_DM.Trim()),
- IsEditable = db.IsEditable
- }
- ).ToList();
- var allDictionaryList = insertDictionaryList.Concat(updateDictionaryList).ToList();
- var insertList = (from all in allFacultyList
- from college in dbCollegeList.Where(x => x.No == all.SSYXB_USERDM.Trim())
- from dic in allDictionaryList.Where(x => x.Code == all.USER_DM.Trim())
- from db in dbFacultyList.Where(x => x.Code == all.USER_DM.Trim()).DefaultIfEmpty()
- where db == null
- select new CF_Facultymajor
- {
- FacultymajorID = Guid.NewGuid(),
- CollegeID = college.CollegeID,
- Code = all.USER_DM.Trim(),
- Name = all.ZWMC.Trim(),
- Abbreviation = null,
- EnglishName = all.YWMC?.Trim(),
- StandardID = dic.Value,
- RecordStatus = (int)SYS_STATUS.USABLE,
- CreateTime = nowTime,
- ModifyTime = nowTime
- }).ToList();
- var updateList = (from all in allFacultyList
- from college in dbCollegeList.Where(x => x.No == all.SSYXB_USERDM.Trim())
- from dic in allDictionaryList.Where(x => x.Code == all.USER_DM.Trim())
- from db in dbFacultyList.Where(x => x.Code == all.USER_DM.Trim())
- select new CF_Facultymajor
- {
- FacultymajorID = db.FacultymajorID,
- CollegeID = college.CollegeID,
- Code = all.USER_DM.Trim(),
- Name = all.ZWMC.Trim(),
- Abbreviation = db.Abbreviation,
- EnglishName = all.YWMC?.Trim(),
- StandardID = dic.Value,
- EducationID = db.EducationID,
- LearningformID = db.LearningformID,
- LearnSystem = db.LearnSystem,
- ScienceclassID = db.ScienceclassID,
- LearningstyleID = db.LearningstyleID,
- LearnPositionID = db.LearnPositionID,
- TeacherIdentification = db.TeacherIdentification,
- SetTime = db.SetTime,
- Remark = db.Remark,
- RecordStatus = (int)SYS_STATUS.USABLE,
- CreateUserID = db.CreateUserID,
- CreateTime = db.CreateTime,
- ModifyUserID = db.ModifyUserID,
- ModifyTime = nowTime
- }).ToList();
- using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
- {
- UnitOfWork.BulkInsert(insertDictionaryList);
- UnitOfWork.BatchUpdate(updateDictionaryList);
- UnitOfWork.BulkInsert(insertList);
- UnitOfWork.BatchUpdate(updateList);
- scope.Complete();
- }
- ParameterServices.Value.SaveTo(CF_ParameterType.SynchFacultyLastTime, nowTime);
- }
- }
- }
|