Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        /// <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
                {
                    // 数据模型映射失败
                    // 可能原因,与之相关的其他表数据不存在
                }
            }
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 删除目录,将在事务环境中执行以下操作
        ///  1. 删除此目录及所有子目录
        ///  2. 删除此目录及所有子目录下的文件
        ///  3. 删除此与此目录下所有文件关联的关键字搜索结果数据
        ///  4. 将操作同步到DbUpdateLog表中
        ///  5. 将操作日志记录到OperateLog表中
        /// </summary>
        /// <param name="id">待删除的目录Id</param>
        /// <returns></returns>
        private bool DeleteDirectoryAndChildren(int id)
        {
            var dirBll    = new TraficFileTypeBll();
            var dirList   = dirBll.QueryList("IsDelete=0", new[] { nameof(TraficFileType.Id), nameof(TraficFileType.ParentId), nameof(TraficFileType.TypeName) }).ToList();
            var deleteDir = dirList.Find(dir => dir.Id == id);

            if (deleteDir == null)
            {
                return(false);
            }

            var fileBll  = new TraficFilesBll();
            var fileList = fileBll.QueryList("IsDelete=0", new[] { nameof(TraficFiles.Id), nameof(TraficFiles.TypeId) }).ToList();

            // 所有待删除的目录Id
            var dirDeleteIdList = new List <int> {
                id
            };

            FindChildDirIds(dirList, id, dirDeleteIdList);

            // 所有待删除的文件Id
            var fileDeleteIdList = fileList.Where(file => dirDeleteIdList.Contains(file.TypeId)).Select(file => file.Id).ToList();

            // 所有待删除的搜索结果Id
            var searchBll    = new TraficSearchResultBll();
            var searchSql    = $"TraficFileId IN({string.Join(",", fileDeleteIdList.Count == 0 ? new List<int> { 0 } : fileDeleteIdList)})"; // 不能让sql语句中IN()中的字符串为空
            var searchIdList = searchBll.QueryList(searchSql, new[] { nameof(TraficSearchResult.Id) })
                               .Select(item => item.Id).ToList();

            // 操作日志
            var log = $"删除了目录[{deleteDir.TypeName}]及其所有的子目录和子文件";

            // 准备sql语句
            var dirDeleteSql    = $"UPDATE TraficFileType SET IsDelete=1 WHERE Id IN({string.Join(",", dirDeleteIdList)})";
            var fileDeleteSql   = $"UPDATE TraficFiles SET IsDelete=1 WHERE Id IN({string.Join(",", fileDeleteIdList)})";
            var searchDeleteSql = $"DELETE FROM TraficSearchResult WHERE TraficFileId IN({string.Join(",", fileDeleteIdList)})";

            // 准备执行委托
            var         logBll                = new OperateLogBll();
            var         loginUser             = LoginStatus.GetLoginId();
            Func <bool> deleteDirs            = () => dirBll.ExecuteSql(dirDeleteSql) == dirDeleteIdList.Count;
            Func <bool> deleteFiles           = () => fileDeleteIdList.Count == 0 ? true : fileBll.ExecuteSql(fileDeleteSql) == fileDeleteIdList.Count;
            Func <bool> deleleSearch          = () => searchIdList.Count == 0 ? true : searchBll.ExecuteSql(searchDeleteSql) == searchIdList.Count;
            Func <bool> insertDirUpdateLog    = () => { DataUpdateLog.BulkUpdate(nameof(TraficFileType), dirDeleteIdList, DataUpdateType.Delete); return(true); };
            Func <bool> insertFileUpdateLog   = () => { DataUpdateLog.BulkUpdate(nameof(TraficFiles), fileDeleteIdList, DataUpdateType.Delete); return(true); };
            Func <bool> insertSearchUpdateLog = () => { DataUpdateLog.BulkUpdate(nameof(TraficSearchResult), searchIdList, DataUpdateType.Delete); return(true); };
            Func <bool> insertOperateLog      = () => logBll.Add(nameof(TraficFileType), id, DataUpdateType.Delete, loginUser, log);

            // 执行事务
            var success = dirBll.ExecuteTransation(
                deleteDirs,
                deleteFiles,
                deleleSearch,
                insertDirUpdateLog,
                insertFileUpdateLog,
                insertSearchUpdateLog,
                insertOperateLog
                );

            return(success);
        }
Exemplo n.º 14
0
        public JsonResult SaveQuota()
        {
            var quotaJson = Request["quota"];

            if (string.IsNullOrEmpty(quotaJson))
            {
                return(Json(ErrorModel.InputError));
            }

            var quota = JsonHelper.Deserialize <InstructorQuota>(quotaJson);

            if (quota == null)
            {
                return(Json(ErrorModel.InputError));
            }

            var standardJson = Request["standard"];

            if (quota.NeedReview && string.IsNullOrEmpty(standardJson))
            {
                return(Json(ErrorModel.InputError));
            }

            var standardList = JsonHelper.Deserialize <List <InstructorReviewStandard> >(standardJson);

            if (quota.NeedReview && (standardList == null || standardList.Count == 0))
            {
                return(Json(ErrorModel.InputError));
            }

            var updateType = quota.Id == 0 ? DataUpdateType.Insert : DataUpdateType.Update;

            bool success;
            var  quotaBll = new InstructorQuotaBll();

            if (quota.Id > 0)
            {
                success = quotaBll.Update(quota);
            }
            else
            {
                quotaBll.Insert(quota);
                success = quota.Id > 0;
            }

            if (success)
            {
                DataUpdateLog.SingleUpdate(typeof(InstructorQuota).Name, quota.Id, updateType);

                if (standardList != null && standardList.Count > 0)
                {
                    var standardToInsert = standardList.Where(s => s.Id == 0).ToList();
                    if (standardToInsert.Any())
                    {
                        standardToInsert.ForEach(s => s.InstructorQuotaId = quota.Id);

                        var standardBll = new InstructorReviewStandardBll();
                        standardBll.BulkInsert(standardToInsert);
                    }
                }

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Exemplo n.º 15
0
        /// <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);
            }
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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 }));
        }