Beispiel #1
0
        public JsonResult GetDeparts()
        {
            var departBll = new DepartInfoBll();
            var list      = departBll.QueryList("IsDelete=0");

            return(Json(ErrorModel.GetDataSuccess(list)));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        public void TestUpdateEditedData()
        {
            var updateInstance = new DepartmentMigration();

            updateInstance.UpdateEditedData();

            var departs      = new DepartInfoBll().QueryAll().ToList();
            var editedDepart = departs.Find(d => d.DepartmentName == "呼南运用车间");

            editedDepart.Should().NotBeNull();

            var dbUpdateLog = new DbUpdateLogBll().QueryList("TableName='DepartInfo' AND UpdateType=2");

            dbUpdateLog.Should().HaveCount(2);
        }
Beispiel #4
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();
        }
Beispiel #5
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));
        }
Beispiel #6
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));
        }
Beispiel #7
0
        public void TestImportNewData()
        {
            TestSuite.CleanTestDb();

            var importInstance = new DepartmentMigration();

            importInstance.ImportNewData();

            var departBll = new DepartInfoBll();
            var departs   = departBll.QueryAll().ToList();

            departs.Should().HaveCount(37, "because the table 'Y_JCYY_BASEDEPARTMENT' in oracle has 37 rows.");
            //departs.Should().Contain(depart => depart.DepartmentName == "集宁机务段");

            var jnDepot = departs.Find(d => d.DepartmentName == "集宁机务段");

            jnDepot.Should().NotBeNull();
            jnDepot?.DepartmentName.Should().NotBeNullOrEmpty().And.Be("集宁机务段");
            jnDepot?.ParentId.Should().Be(0);

            var jnyyc = departs.Find(d => d.DepartmentName == "集宁运用车间");

            jnyyc.Should().NotBeNull();
            jnyyc?.ParentId.Should().Be(jnDepot?.Id);

            var dbupdateLogBll = new DbUpdateLogBll();
            var dbupdateLogs   = dbupdateLogBll.QueryList($"TableName='{nameof(DepartInfo)}'").ToList();

            dbupdateLogs.Should().HaveCount(37);

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

            relations.Should().HaveCount(37);

            var maxBll     = new OracleTableMaxIdBll();
            var maxIdModel = maxBll.QuerySingle($"TableName='Y_JCYY_BASEDEPARTMENT'");

            maxIdModel.Should().NotBeNull();
            maxIdModel.MaxId.Should().Be("404100000");
        }
Beispiel #8
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));
        }
Beispiel #9
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;
                }
            }
        }