Пример #1
0
        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));
        }
Пример #2
0
        public void TestImportNewData()
        {
            var importInstance = new PostMigragion();

            importInstance.ImportNewData();

            var posts = new PostsBll().QueryAll();

            posts.Should()
            .HaveCount(192, "because there are only 192 rows data in the table j_jcyy_basepost of data source");

            var dbUpdateLogs = new DbUpdateLogBll().QueryAll();

            dbUpdateLogs.Should().HaveCount(192, "because I just insert 192 rows data to the table Posts");

            var relations = new PrimaryIdRelationBll().QueryAll();

            relations.Should()
            .HaveCount(192, "becaust there are only 192 rows data in the table j_jcyy_basepost of data source");

            var maxId = new OracleTableMaxIdBll().QuerySingle($"TableName='{nameof(J_JCYY_BASEPOST)}'");

            maxId.Should().NotBeNull();
            maxId?.MaxId.Should().Be("226");
        }
Пример #3
0
        public JsonResult GetPositions()
        {
            var postBll = new PostsBll();
            var posts   = postBll.QueryList("IsDelete=0");

            return(Json(ErrorModel.GetDataSuccess(posts)));
        }
Пример #4
0
        public void TestUpdateEditedData()
        {
            var updateInstance = new PostMigragion();

            updateInstance.UpdateEditedData();

            var editedModel = new PostsBll().QuerySingle("PostName='测试修改安全监控员'");

            editedModel.Should().NotBeNull();

            var dbUpdateLog = new DbUpdateLogBll().QuerySingle($"TableName='{nameof(Posts)}' AND UpdateType=2");

            dbUpdateLog.Should().NotBeNull();
        }
Пример #5
0
        private void Uniq(ref List <Posts> posts, ref List <DepartInfo> departs, ref List <PersonInfo> staff)
        {
            List <Posts>      _posts   = new PostsBll().QueryAll().ToList();
            List <DepartInfo> _departs = new DepartInfoBll().QueryAll().ToList();
            List <string>     _workNos = new PersonInfoBll()
                                         .QueryList("IsDelete=0", new[] { nameof(PersonInfo.WorkNo) })
                                         .Select(p => p.WorkNo).ToList();

            posts   = Distinct(posts, p => p.PostName).Where(p => p.PostName != string.Empty).ToList();
            departs = Distinct(departs, d => d.DepartmentName).Where(d => d.DepartmentName != string.Empty).ToList();

            posts   = posts.Where(p => !Contains(_posts, item => item.PostName == p.PostName)).ToList();
            departs = departs.Where(d => !Contains(_departs, item => item.DepartmentName == d.DepartmentName)).ToList();
            staff   = staff.Where(s => !_workNos.Contains(s.WorkNo)).ToList();
        }
Пример #6
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));
        }
Пример #7
0
        private void Persistent(List <Posts> posts, List <DepartInfo> departs, List <PersonInfo> staff)
        {
            var staffBll    = new PersonInfoBll();
            var dbUpdateBll = new DbUpdateLogBll();

            Func <bool>[] delegates = new Func <bool> [3];
            delegates[0] = () =>
            {
                if (posts.Count > 0)
                {
                    var postBll = new PostsBll();
                    var maxId   = postBll.GetMaxId();
                    postBll.BulkInsert(posts);

                    var ids    = postBll.QueryList("Id>" + maxId, new[] { nameof(Posts.Id) }).Select(p => p.Id);
                    var dbLogs = ids.Select(id => new DbUpdateLog {
                        TableName = nameof(Posts), TargetId = id, UpdateType = 1, UpdateTime = DateTime.Now
                    });
                    dbUpdateBll.BulkInsert(dbLogs);
                }
                return(true);
            };
            delegates[1] = () =>
            {
                if (departs.Count > 0)
                {
                    var departBll = new DepartInfoBll();
                    var maxId     = departBll.GetMaxId();
                    departBll.BulkInsert(departs);

                    var ids    = departBll.QueryList("Id>" + maxId, new[] { nameof(DepartInfo.Id) }).Select(p => p.Id);
                    var dbLogs = ids.Select(id => new DbUpdateLog {
                        TableName = nameof(DepartInfo), TargetId = id, UpdateType = 1, UpdateTime = DateTime.Now
                    });
                    dbUpdateBll.BulkInsert(dbLogs);
                }
                return(true);
            };
            delegates[2] = () =>
            {
                List <Posts>      _posts   = new PostsBll().QueryAll().ToList();
                List <DepartInfo> _departs = new DepartInfoBll().QueryAll().ToList();
                staff.ForEach(s =>
                {
                    // 根据前面用 PersonId 存储的部门名称找到此员工对应的部门
                    // 根据前面用 PhotoPath 存储的职务名称找到此员工对应的职务
                    var depart     = _departs.Find(d => d.DepartmentName == s.PersonId);
                    var post       = _posts.Find(p => p.PostName == s.PhotoPath);
                    s.DepartmentId = depart?.Id ?? 0;
                    s.PostId       = post?.Id ?? 0;
                    s.PersonId     = string.Empty;
                    s.PhotoPath    = string.Empty;
                });

                var maxId = staffBll.GetMaxId();
                staffBll.BulkInsert(staff);

                var ids    = staffBll.QueryList("Id>" + maxId, new[] { nameof(PersonInfo.Id) }).Select(p => p.Id);
                var dbLogs = ids.Select(id => new DbUpdateLog {
                    TableName = nameof(PersonInfo), TargetId = (int)id, UpdateType = 1, UpdateTime = DateTime.Now
                });
                dbUpdateBll.BulkInsert(dbLogs);

                return(true);
            };

            // 若插入失败,则尝试五次
            for (var i = 0; i < 5; i++)
            {
                var success = staffBll.ExecuteTransation(delegates);
                if (success)
                {
                    return;
                }
            }
        }