public JsonResult AddKeywords(string keywords) { if (string.IsNullOrEmpty(keywords)) { return(Json(ErrorModel.InputError)); } var model = new TraficKeywords { Keywords = keywords }; var keywordsBll = new TraficKeywordsBll(); keywordsBll.Insert(model); if (model.Id > 0) { DataUpdateLog.SingleUpdate(typeof(TraficKeywords).Name, model.Id, DataUpdateType.Insert); SearchHelper.AddSearchTask(2, model.Id); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult DeleteDepart(int id) { var personBll = new PersonInfoBll(); var personCount = personBll.CountDepartPerson(id); if (personCount > 0) { return(Json(ErrorModel.DeleteForbidden)); } var departBll = new DepartInfoBll(); var subDeparts = departBll.QueryList("IsDelete=0 AND ParentId=" + id); if (subDeparts.Any()) { return(Json(ErrorModel.DeleteForbidden)); } var success = departBll.DeleteSoftly(id); if (success) { DataUpdateLog.SingleUpdate(typeof(DepartInfo).Name, id, DataUpdateType.Delete); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult Delete(int id, int type) { bool success = false; if (type == 1) { success = DeleteDirectoryAndChildren(id); } else if (type == 2) { var fileBll = new ViewTraficFilesBll(); var file = fileBll.QuerySingle(id); if (file == null) { success = false; } else { var log = $"删除了目录[{file.TypeName}]下的文件《{file.FileName}》"; var logBll = new OperateLogBll(); success = fileBll.ExecuteTransation( () => fileBll.DeleteSoftly(id), () => DataUpdateLog.SingleUpdate(nameof(TraficFiles), id, DataUpdateType.Delete), () => logBll.Add(nameof(TraficFiles), id, DataUpdateType.Delete, LoginStatus.GetLoginId(), log) ); } } if (success) { return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult AddPostion(string postName) { postName = postName.Trim(); if (string.IsNullOrEmpty(postName)) { return(Json(ErrorModel.InputError)); } var posts = new Posts { PostName = postName }; var postBll = new PostsBll(); var condition = string.Format("IsDelete=0 AND PostName='{0}'", postName); if (postBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } postBll.Insert(posts); if (posts.Id > 0) { DataUpdateLog.SingleUpdate(typeof(Posts).Name, posts.Id, DataUpdateType.Insert); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult DeleteDirectory(int id) { var fileTypeBll = new TraficFileTypeBll(); if (fileTypeBll.Exists("ParentId=" + id)) { return(Json(ErrorModel.DeleteForbidden)); } var fileBll = new TraficFilesBll(); if (fileBll.Exists("IsDelete=0 AND TypeId=" + id)) { return(Json(ErrorModel.DeleteForbidden)); } var success = fileTypeBll.Delete(id); if (success) { DataUpdateLog.SingleUpdate(typeof(TraficFileType).Name, id, DataUpdateType.Delete); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult AddExamType(string name) { if (string.IsNullOrWhiteSpace(name)) { return(Json(ErrorModel.InputError)); } var typeBll = new ExamTypeBll(); var condition = string.Format("TypeName='{0}'", name.Trim()); if (typeBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } var typeModel = new ExamType { TypeName = name }; typeBll.Insert(typeModel); if (typeModel.Id > 0) { DataUpdateLog.SingleUpdate(typeof(ExamType).Name, typeModel.Id, DataUpdateType.Insert); return(Json(ErrorModel.GetDataSuccess(typeModel.Id))); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult StationEdit() { var stationJson = Request["station"]; var station = JsonHelper.Deserialize <BaseStation>(stationJson); var updateType = station.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; // 更新车站 var stationUpdateRes = false; var stationBll = new BaseStationBll(); if (station.Id > 0) { stationUpdateRes = stationBll.Update(station); } else { var condition = string.Format("StationName='{0}' AND IsDelete=0", station.StationName); if (stationBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } var insertedStation = stationBll.Insert(station); stationUpdateRes = insertedStation.Id > 0; } // 更新文件 if (stationUpdateRes) { // 写入更新记录 DataUpdateLog.SingleUpdate(typeof(BaseStation).Name, station.Id, updateType); var filesJson = Request["files"]; var files = JsonHelper.Deserialize <StationFiles[]>(filesJson); if (!files.Any()) { return(Json(ErrorModel.OperateSuccess)); } files.ForEach(f => { f.StationId = station.Id; }); var filesToInsert = files.Where(f => f.Id == 0); var filesBll = new StationFilesBll(); var maxId = (int)filesBll.GetMaxId(); filesBll.BulkInsert(filesToInsert); // 写入更新记录 DataUpdateLog.BulkUpdate(typeof(StationFiles).Name, maxId); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult LineEdit() { var lineJson = Request["line"]; var line = JsonHelper.Deserialize <BaseLine>(lineJson); var updateType = line.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; // 更新线路 var lineUpdateRes = false; var lineBll = new BaseLineBll(); if (line.Id > 0) { lineUpdateRes = lineBll.Update(line); } else { var condition = string.Format("LineName='{0}' AND IsDelete=0", line.LineName); if (lineBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } var insertedLine = lineBll.Insert(line); lineUpdateRes = insertedLine.Id > 0; } // 更新车站 if (lineUpdateRes) { // 写入更新记录 DataUpdateLog.SingleUpdate(typeof(BaseLine).Name, line.Id, updateType); var stationsJson = Request["stations"]; var stations = JsonHelper.Deserialize <LineStations[]>(stationsJson); if (!stations.Any()) { return(Json(ErrorModel.OperateSuccess)); } stations.ForEach(f => { f.LineId = line.Id; }); var stationsToInsert = stations.Where(f => f.Id == 0); var lineStationsBll = new LineStationsBll(); var maxId = (int)lineStationsBll.GetMaxId(); lineStationsBll.BulkInsert(stationsToInsert); // 写入更新记录 DataUpdateLog.BulkUpdate(typeof(LineStations).Name, maxId); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult DeleteNotify(int id) { var bll = new ExamNotifyBll(); var success = bll.ExecuteTransation( () => bll.Delete(id), () => DataUpdateLog.SingleUpdate(nameof(ExamNotify), id, DataUpdateType.Delete) ); return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed)); }
public JsonResult DeleteStationFiles(int fileId) { var stationFilesBll = new StationFilesBll(); var success = stationFilesBll.DeleteSoftly(fileId); if (success) { DataUpdateLog.SingleUpdate(typeof(StationFiles).Name, fileId, DataUpdateType.Delete); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult PersonEdit(PersonInfo person) { if (person == null) { return(Json(ErrorModel.InputError)); } var personBll = new PersonInfoBll(); // 验证工号重复性 var condition = person.Id > 0 ? $"WorkNo='{person.WorkNo}' AND Id<>{person.Id} AND IsDelete=0" : $"WorkNo='{person.WorkNo}' AND IsDelete=0"; if (personBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } // 获取姓名的简拼 person.Spell = PinyinHelper.GetInitials(person.Name).ToLower(); person.UpdateTime = DateTime.Now; var dbUpdateType = person.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; var success = false; if (person.Id > 0) { success = personBll.Update(person); } else { // 第一次录入时将密码设置为工号后四位 var password = person.WorkNo.Substring(person.WorkNo.Length - 5); // person.Password = password.GetMd5(); // @FrancisTan 修改于 2017-02-17 // 目的是为了统一密码的生成,保证一致性 person.Password = EncryptHelper.EncryptPassword(password); success = personBll.Insert(person).Id > 0; } if (success) { DataUpdateLog.SingleUpdate(typeof(PersonInfo).Name, (int)person.Id, dbUpdateType); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult DeleteTrainNoLine(int id) { var trainNoLineBll = new TrainNoLineBll(); var deleteSuccess = trainNoLineBll.Delete(id); if (deleteSuccess) { DataUpdateLog.SingleUpdate(typeof(TrainNoLine).Name, id, DataUpdateType.Delete); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult Save(string json) { var list = JsonHelper.Deserialize <List <TrainMoment> >(json); if (list == null || !list.Any()) { return(Json(ErrorModel.OperateSuccess)); } // 对列车时刻的更新只存在两种情况 // 1 某车次的列车时刻第一次添加,此时将所有车站的列车时刻表插入数据库 // 2 对某车次的某些车站的列车时刻进行更新 var trainMomentBll = new TrainMomentBll(); var tableName = typeof(TrainMoment).Name; var isInsert = list[0].Id == 0; if (isInsert) { var maxId = trainMomentBll.GetMaxId(); trainMomentBll.BulkInsert(list); DataUpdateLog.BulkUpdate(tableName, (int)maxId); return(Json(ErrorModel.OperateSuccess)); } var success = trainMomentBll.ExecuteTransation(() => { foreach (var item in list) { if (!trainMomentBll.Update(item)) { return(false); } DataUpdateLog.SingleUpdate(tableName, item.Id, DataUpdateType.Update); } return(true); }); if (success) { return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult Delete(int id) { var bll = new AnnouncementBll(); var success = bll.ExecuteTransation( () => bll.Delete(id), () => DataUpdateLog.SingleUpdate(nameof(Announcement), id, DataUpdateType.Delete) ); if (success) { return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult DeleteFiles(int id) { var fileBll = new TraficFilesBll(); var success = fileBll.DeleteSoftly(id); if (success) { DataUpdateLog.SingleUpdate(typeof(TraficFiles).Name, id, DataUpdateType.Delete); DeleteSearchResult(1, id); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult UpdateNotify(string json) { var model = JsonHelper.Deserialize <ExamNotify>(json); if (null != model) { var bll = new ExamNotifyBll(); var success = bll.ExecuteTransation( () => bll.Update(model), () => DataUpdateLog.SingleUpdate(nameof(ExamNotify), model.Id, DataUpdateType.Update) ); return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed)); } return(Json(ErrorModel.InputError)); }
public JsonResult Save(string json) { var model = JsonHelper.Deserialize <Announcement>(json); if (model == null) { return(Json(ErrorModel.InputError)); } var loginUser = LoginStatus.GetLoginUser(); model.SystemUserId = loginUser.Id; model.DepartmentId = loginUser.DepartmentId; model.DepartmentName = loginUser.DepartmentName; model.PubTime = DateTime.Now; var updateType = model.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; bool success; var bll = new AnnouncementBll(); if (model.Id > 0) { success = bll.Update(model); } else { model = bll.Insert(model); success = model.Id > 0; } if (success) { var logBll = new OperateLogBll(); var dic = new Dictionary <int, string> { { 1, "普通公告" }, { 2, "事故预警" }, { 3, "附件4" } }; var log = $"发布了[{dic[model.BusinessType]}]类型的公告"; logBll.Add(nameof(Announcement), model.Id, updateType, LoginStatus.GetLoginId(), log); DataUpdateLog.SingleUpdate(nameof(Announcement), model.Id, updateType); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult AddDepart() { var departJson = Request["depart"]; var depart = JsonHelper.Deserialize <DepartInfo>(departJson); var departBll = new DepartInfoBll(); var success = departBll.Insert(depart).Id > 0; if (success) { DataUpdateLog.SingleUpdate(typeof(DepartInfo).Name, depart.Id, DataUpdateType.Insert); return(Json(ErrorModel.AddDataSuccess(depart.Id))); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult Rename(int id, string name) { var viewFileBll = new ViewTraficFilesBll(); var fileBll = new TraficFilesBll(); var logBll = new OperateLogBll(); var origin = viewFileBll.QuerySingle(id); var log = $"将目录[{origin.TypeName}]下的文件[{origin.FileName}]重命名为[{name}]"; var success = fileBll.ExecuteTransation( () => fileBll.Update(new TraficFiles { Id = id, FileName = name }, new string[] { nameof(TraficFiles.FileName) }), () => DataUpdateLog.SingleUpdate(nameof(TraficFiles), id, DataUpdateType.Update), () => logBll.Add(nameof(TraficFiles), id, DataUpdateType.Update, LoginStatus.GetLoginId(), log) ); return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed)); }
public JsonResult AddDirectory(string directory) { var model = JsonHelper.Deserialize <TraficFileType>(directory); if (model == null) { return(Json(ErrorModel.InputError)); } var dirBll = new TraficFileTypeBll(); // 验证目录是否重名 var condition = $"ParentId={model.ParentId} AND TypeName='{model.TypeName}' AND IsDelete=0"; if (dirBll.Exists(condition)) { return(Json(ErrorModel.DirectoryExists)); } // 准备数据库操作事务 var updateType = model.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; var log = $"添加了目录[{model.TypeName}]"; Func <bool> doAddOrUpdate = () => dirBll.Insert(model).Id > 0; if (model.Id > 0) { var viewDirBll = new ViewTraficFileTypeBll(); var origin = viewDirBll.QuerySingle(model.Id); var newDepartName = new DepartInfoBll().QuerySingle(model.DepartmentId, new[] { nameof(DepartInfo.DepartmentName) }).DepartmentName; log = $"将目录由[{origin.TypeName}-{origin.DepartmentName}-{(origin.IsPublic ? "公共文件夹" : "私有文件夹")}]更新为[{model.TypeName}-{newDepartName}-{(model.IsPublic ? "公共文件夹" : "私有文件夹")}]"; doAddOrUpdate = () => dirBll.Update(model); } // 执行事务 var loginUser = LoginStatus.GetLoginId(); var logBll = new OperateLogBll(); var success = dirBll.ExecuteTransation( doAddOrUpdate, () => DataUpdateLog.SingleUpdate(nameof(TraficFileType), model.Id, updateType), () => logBll.Add(nameof(TraficFileType), model.Id, updateType, loginUser, log) ); return(Json(success ? ErrorModel.AddDataSuccess(model.Id) : ErrorModel.OperateFailed)); }
public JsonResult DeleteLineStation(int lineStationId) { if (lineStationId == 0) { return(Json(ErrorModel.OperateSuccess)); } var lineStationBll = new LineStationsBll(); var success = lineStationBll.Delete(lineStationId); if (success) { DataUpdateLog.SingleUpdate(typeof(LineStations).Name, lineStationId, DataUpdateType.Delete); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult SaveRouter() { var json = Request["json"]; if (string.IsNullOrEmpty(json)) { return(Json(ErrorModel.InputError)); } var model = JsonHelper.Deserialize <InstructorRouterPosition>(json); if (model == null) { return(Json(ErrorModel.InputError)); } model.AddTime = DateTime.Now; var updateType = model.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; bool success; var bll = new InstructorRouterPositionBll(); if (model.Id > 0) { success = bll.Update(model); } else { model = bll.Insert(model); success = model.Id > 0; } if (success) { DataUpdateLog.SingleUpdate(nameof(InstructorRouterPosition), model.Id, updateType); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
/// <summary> /// 执行数据导入到具体表 /// </summary> /// <param name="data">从Oracle数据库中获取到的新增数据集合</param> protected virtual void ExecuteImport(IEnumerable <TOracle> data) { IList <TOracle> oracleData = data.ToList(); if (DataProcessEvent != null) { oracleData = DataProcessEvent(data); } foreach (var model in oracleData) { dynamic sqlModel = MapEntity(model); if (sqlModel != null) { // 数据插入事务 Func <bool> importTransaction = () => { var success = SqlserverBaseBll.Insert(sqlModel).Id > 0; if (success) { // 将数据库更新同步到app DataUpdateLog.SingleUpdate(SqlserverTableName, Convert.ToInt32(sqlModel.Id), DataUpdateType.Insert); // 更新主键关系 return(UpdatePrimaryRelation(model, sqlModel)); } return(false); }; // 执行事务 SqlserverBaseBll.ExecuteTransation(importTransaction); } else { // 数据模型映射失败 // 可能原因,与之相关的其他表数据不存在 } } }
public JsonResult AddOrUpdateDepart(DepartInfo depart) { if (depart != null) { var bll = new DepartInfoBll(); if (bll.Exists($"DepartmentName='{depart.DepartmentName}' AND IsDelete=0")) { return(Json(ErrorModel.ExistSameItem)); } var updateType = depart.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; var success = bll.ExecuteTransation( () => depart.Id == 0 ? bll.Insert(depart).Id > 0 : bll.Update(depart), () => DataUpdateLog.SingleUpdate(nameof(DepartInfo), depart.Id, updateType) ); return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed)); } return(Json(ErrorModel.InputError)); }
public JsonResult SaveNotify(string json) { var model = JsonHelper.Deserialize <ExamNotify>(json); if (model == null) { return(Json(ErrorModel.InputError)); } var notifyBll = new ExamNotifyBll(); notifyBll.Insert(model); if (model.Id > 0) { DataUpdateLog.SingleUpdate(typeof(ExamNotify).Name, model.Id, DataUpdateType.Insert); return(Json(ErrorModel.OperateSuccess)); } return(Json(ErrorModel.OperateFailed)); }
public JsonResult AddOrUpdatePost(Posts model) { if (model != null) { var bll = new PostsBll(); if (bll.Exists($"PostName='{model.PostName}' AND IsDelete=0")) { return(Json(ErrorModel.ExistSameItem)); } var isUpdate = model.Id > 0; var updateType = isUpdate ? DataUpdateType.Update : DataUpdateType.Insert; var success = bll.ExecuteTransation( () => isUpdate ? bll.Update(model) : bll.Insert(model).Id > 0, () => DataUpdateLog.SingleUpdate(nameof(Posts), model.Id, updateType) ); return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed)); } return(Json(ErrorModel.InputError)); }
public JsonResult AddOrUpdateRouter(InstructorRouterPosition model) { if (model != null) { var isUpdate = model.Id > 0; var updateType = isUpdate ? DataUpdateType.Update : DataUpdateType.Insert; var bll = new InstructorRouterPositionBll(); Func <bool> doUpdate = () => bll.Insert(model).Id > 0; if (isUpdate) { doUpdate = () => bll.Update(model); } var success = bll.ExecuteTransation( doUpdate, () => DataUpdateLog.SingleUpdate(nameof(InstructorRouterPosition), model.Id, updateType) ); return(Json(success ? ErrorModel.OperateSuccess : ErrorModel.OperateFailed)); } return(Json(ErrorModel.InputError)); }
public JsonResult AddFiles() { var typeId = Request["typeId"].ToInt32(); var departId = Request["depart"].ToInt32(); if (typeId == 0 || departId == 0) { return(Json(new { msg = ErrorModel.InputError })); } // 将文件保存到本地 var uploadRes = UploadHelper.FileUpload(); var filePathInfo = uploadRes as FilePathInfo; if (filePathInfo == null) { return(Json(new { msg = uploadRes })); } var fileBll = new TraficFilesBll(); // 验证文件是否重名 var condition = $"IsDelete=0 AND TypeId={typeId} AND FileName='{filePathInfo.OriginalFileName}'"; if (fileBll.Exists(condition)) { return(Json(ErrorModel.FileExists)); } var loginUser = LoginStatus.GetLoginId(); var fileModel = new TraficFiles { FileExtension = filePathInfo.FileExtension, FileName = filePathInfo.OriginalFileName, FilePath = filePathInfo.FileRelativePath, OriginFilePath = filePathInfo.FileRelativePath, FileSize = filePathInfo.FileSize, TypeId = typeId, CreatorId = loginUser, DepartmentId = departId }; var logBll = new OperateLogBll(); var dirBll = new TraficFileTypeBll(); var dir = dirBll.QuerySingle(typeId); var log = $"在目录[{dir.TypeName}]下添加了文件《{filePathInfo.OriginalFileName}》"; // 执行插入操作、数据库更新日志插入操作以及后台操作日志插入操作 var success = fileBll.ExecuteTransation( () => fileBll.Insert(fileModel).Id > 0, () => DataUpdateLog.SingleUpdate(nameof(TraficFiles), fileModel.Id, DataUpdateType.Insert), () => logBll.Add(nameof(TraficFiles), fileModel.Id, DataUpdateType.Insert, loginUser, log) ); if (success) { // 开启新线程执行将 office 文件转换为 html 的任务 // 以避免阻塞网络请求线程,造成用户长时间的等待 Task.Factory.StartNew(() => FormatFile(fileModel)); return(Json(new { msg = ErrorModel.OperateSuccess, data = uploadRes, fileId = fileModel.Id, fileModel })); } return(Json(new { msg = ErrorModel.OperateFailed })); }
public JsonResult SaveTrainNo() { var trainNoJson = Request["trainNo"]; var trainNo = JsonHelper.Deserialize <TrainNo>(trainNoJson); if (trainNo == null) { return(Json(ErrorModel.InputError)); } var updateType = trainNo.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; var trainNoBll = new TrainNoBll(); var updateSuccess = false; if (trainNo.Id > 0) { updateSuccess = trainNoBll.Update(trainNo); } else { // 验证是否存在相同的车次 var condition = string.Format("FullName='{0}' AND IsDelete=0", trainNo.FullName); if (trainNoBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } var insertedTrainNo = trainNoBll.Insert(trainNo); updateSuccess = insertedTrainNo.Id > 0; } if (!updateSuccess) { return(Json(ErrorModel.OperateFailed)); } DataUpdateLog.SingleUpdate(typeof(TrainNo).Name, trainNo.Id, updateType); var linesJson = Request["lines"]; var lines = JsonHelper.Deserialize <TrainNoLine[]>(linesJson); if (lines == null || !lines.Any()) { return(Json(ErrorModel.InputError)); } var linesToInsert = lines.Where(line => line.Id == 0).ToArray(); if (linesToInsert.Any()) { linesToInsert.ForEach(line => { line.TrainNoId = trainNo.Id; }); var trainNoLineBll = new TrainNoLineBll(); var maxId = (int)trainNoLineBll.GetMaxId(); trainNoLineBll.BulkInsert(linesToInsert); DataUpdateLog.BulkUpdate(typeof(TrainNoLine).Name, maxId); } return(Json(ErrorModel.OperateSuccess)); }
/// <summary> /// 实现更新数据源中被修改过的数据 /// </summary> public void UpdateEditedData() { try { var watch = new Stopwatch(); watch.Start(); var counter = 0; #region 执行数据同步 Logger.Info($"正在执行同步表 {OracleTableName} 中被更新过的数据"); if (!NeedToUpdateAll) { Logger.Info($"由于表 {OracleTableName} 配置了 {nameof(NeedToUpdateAll)} 的值为false,因此跳过同步数据操作"); return; } // 获取关系缓存中与待更新表有关的数据 Logger.Info($"正在执行从缓存中获取与表 {OracleTableName} 所对应的主键关系"); var relations = CacheManager.PrimaryIdCache.Where(item => item.OracleTableName == OracleTableName); Logger.Info("正在执行逐条对比源数据与目标数据的差异性"); foreach (var relation in relations) { // 逐条对比oracle与sqlserver中的数据有无变化 dynamic oracleModel = OracleBaseBll.QuerySingle((object)relation.OraclePrimaryId); dynamic sqlserverModel = SqlserverBaseBll.QuerySingle((object)relation.SqlPrimaryId); if (oracleModel == null) { // 数据源中该数据被删除,目前暂时忽略 } else { if (HasEdited(oracleModel, sqlserverModel)) { // 数据源中的数据被修改过 UpdateSqlserverModel(oracleModel, sqlserverModel); Func <bool> updateTransaction = () => { var success = SqlserverBaseBll.Update(sqlserverModel); if (success) { // 将数据更新同步到数据更新日志表中 DataUpdateLog.SingleUpdate(SqlserverTableName, Convert.ToInt32(sqlserverModel.Id), DataUpdateType.Update); return(true); } return(false); }; // 执行数据同步 var syncSuccess = SqlserverBaseBll.ExecuteTransation(updateTransaction); if (syncSuccess) { counter++; } } // end if } // end else } // end foreach #endregion watch.Stop(); Logger.Info($"本次同步数据结束,共检查 {relations.Count()} 条数据,其中有 {counter} 条数据被更新,共耗时 {watch.Elapsed}"); } catch (Exception ex) { Logger.Error($"在执行同步表 {OracleTableName} 的数据更新时发生异常", ex); } }