コード例 #1
0
ファイル: EHRApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-22
        /// 描述:同步EHR部门
        /// </summary>
        /// <param name="jsonData">部门Json数据</param>
        /// <returns></returns>
        public string SyncBranch(string jsonData)
        {
            var result = new ESBResult();
            DeptModel dept = null;

            if (string.IsNullOrWhiteSpace(jsonData))
            {
                result.Code = "EME0101";
                result.Message = "Json数据空值错误!";
                return JsonHelper.ToJson(result);
            }
            try
            {
                dept = JsonHelper.FromJson<DeptModel>(jsonData);
            }
            catch (Exception ex)
            {
                result.Code = "EME0101";
                result.Message = "Json数据格式错误!";
                return JsonHelper.ToJson(result);
            }

            result = BranchBLL.EditBranch(dept);
            return JsonHelper.ToJson(result);
        }
コード例 #2
0
ファイル: ExamApi.cs プロジェクト: xeon2007/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014.09.19
        /// 描述:更新同步成功的帐号(学员、SA、特殊员工)状态
        /// </summary>
        /// <param name="loginNames"></param>
        /// <returns></returns>
        public string SyncAccountStatus(string loginNames)
        {
            var result = new ESBResult { Code = "000000" };

            if (string.IsNullOrWhiteSpace(loginNames))
            {
                result.Code = "EME0401";
                result.Message = "loginnames json empty";
            }
            else
            {
                try
                {
                    var logginNameList = JsonHelper.FromJson<List<LoginName>>(loginNames);
                    var userNameList = logginNameList.Select(u => u.loginName).ToList();
                    result = StudentBLL.UpdateUserIsSync(userNameList);
                }
                catch (Exception ex)
                {
                    result.Code = "EME0401";
                    result.Message = "loginnames json format error";
                }
            }

            return JsonHelper.ToJson(result);
        }
コード例 #3
0
ファイル: EHRApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-27
        /// 描述:同步EHR部门状态
        /// </summary>
        /// <param name="jsonData">
        ///     deptId:部门Id
        ///     status:101正常,102无效,103删除
        /// </param>
        /// <returns></returns>
        public string SyncBranchStatus(string jsonData)
        {
            var result = new ESBResult();
            BranchStatus deptStatus = null;

            if (string.IsNullOrWhiteSpace(jsonData))
            {
                result.Code = "EME0101";
                result.Message = "Json数据空值错误!";
                return JsonHelper.ToJson(result);
            }
            try
            {
                deptStatus = JsonHelper.FromJson<BranchStatus>(jsonData);
            }
            catch (Exception ex)
            {
                result.Code = "EME0101";
                result.Message = "Json数据格式错误!";
                return JsonHelper.ToJson(result);
            }

            result = BranchBLL.UpdateBranchStatus(deptStatus);
            return JsonHelper.ToJson(result);
        }
コード例 #4
0
        public ActionResult ProcessRequest()
        {
            HttpContextBase context = HttpContext;
            context.Response.ContentType = "text/plain";
            var soapAction = context.Request.Headers["ProduceAction"];
            var requestParams = HttpHelper.ReadRequestData(context);
            LogHelper.WriteLog(soapAction + " jsonData = " + requestParams);
            ResultModel result = null;

            switch (soapAction)
            {
                case "SyncContract":
                    result = contractApi.EmeContractService(requestParams);
                    break;
                case "SyncContractFreeze":
                    result = contractApi.EmeContractDivest(requestParams);
                    break;
                case "SyncContractDelay":
                    result = contractApi.EmeContractDelay(requestParams);
                    break;
                case "SyncUser":
                    result = userApi.EmeUserService(requestParams);
                    break;
                case "SyncReferral":
                    result = referApi.CreateReferral(requestParams);
                    break;
                case "ContractDelete":
                    result = contractApi.EmeContractDelete(requestParams);
                    break;
                default:
                    soapAction = "invalid" + soapAction;
                    result = new ResultModel { code = 200, msg = "invalid ProduceAction" };
                    break;
            }

            var esbResult = new ESBResult { Code = "000000", Message = "成功" };

            if (0 != result.code)
            {
                esbResult.Code = "EME0201";
                esbResult.Message = result.msg;
            }

            var jsonResult = JsonHelper.ToJson(esbResult);
            LogHelper.WriteLog(soapAction + " result = " + jsonResult);
            context.Response.Write(jsonResult);
            return null;
        }
コード例 #5
0
        public ActionResult ProcessRequest()
        {
            HttpContextBase context = HttpContext;
            context.Response.ContentType = "text/plain";
            var soapAction = context.Request.Headers["ProduceAction"];
            var requestParams = HttpHelper.ReadRequestData(context);
            LogHelper.WriteLog(soapAction + " jsonData = " + requestParams);
            string result = string.Empty;

            switch (soapAction)
            {
                case "GetAccountStudents":
                    result = coolApi.GetAccountStudents();
                    break;
                case "SyncAccountStudents":
                    result = coolApi.SyncAccountStudents(requestParams);
                    break;
                case "SyncLessonsResults":
                    result = coolApi.SyncLessonsResults(requestParams);
                    break;
                case "GetLessonNotices":
                    result = coolApi.GetLessonNotices();
                    break;
                case "SyncLessonNotices":
                    result = coolApi.SyncLessonNotices(requestParams);
                    break;

                //case "GetAuths":
                //    result = coolApi.GetAuths();
                //    break;
                //case "SyncAuths":
                //    result = coolApi.SyncAuths(requestParams);
                //    break;
                default:
                    soapAction = "invalid" + soapAction;
                    var temp = new ESBResult { Code = "EME0301", Message = "invalid ProduceAction" };
                    result = JsonHelper.ToJson(temp);
                    break;
            }

            LogHelper.WriteLog(soapAction + " result = " + result);
            context.Response.Write(result);
            return null;
        }
コード例 #6
0
ファイル: BranchBLL.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-27
        /// 描述:同步EHR部门状态
        /// </summary>
        /// <param name="branchStatus"></param>
        /// <returns></returns>
        public static ESBResult UpdateBranchStatus(BranchStatus branchStatus)
        {
            var result = new ESBResult { Code = "000000", Message = "成功" };
            var editUserId = -111;

            try
            {
                using (var edb = new EmeEntities())
                {
                    var remark = branchStatus.DeptId.ToString();
                    // EHR的部门Id对应Branch的Remark

                    var branch = edb.Branch.FirstOrDefault(b => b.Remark == remark);

                    if (null == branch)
                    {
                        result.Code = "EME0101";
                        result.Message = "操作失败,部门Id不存在!";
                    }
                    else
                    {
                        branch.Status = branchStatus.Status;
                        branch.UpdateBy = editUserId;
                        branch.UpdateTime = DateTime.Now;
                        edb.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                // 异常日志消息队列
                QueueManager.AddExceptionLog(new ExceptionLogs()
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-UpdateBranchStatus:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                    IsTreat = false,
                    CreateBy = -1,
                    CreateTime = DateTime.Now
                });

                result.Code = "EME0102";
                result.Message = "数据库操作异常,请联系管理员!";
            }

            return result;
        }
コード例 #7
0
ファイル: StudentBLL.cs プロジェクト: kylin589/EmePro
        //public static ESBResult CreateSyncLessonNotices(List<PreviewModel> lessonList)
        //{
        //    var result = new ESBResult { Code = "000000", Message = "success" };
        //    int active = ConvertEnum.StatusTypeForActive;
        //    if (null == lessonList || !lessonList.Any())
        //    {
        //        result.Code = "EME0301";
        //        result.Message = "json data param error";
        //        return result;
        //    }
        //    using (var edb = new EmeEntities())
        //    {
        //        try
        //        {
        //            foreach (var item in lessonList)
        //            {
        //                // 获取学员编号
        //                var studentId = (from s in edb.Student
        //                                 join u in edb.User on s.UserId equals u.Id
        //                                 where u.Status == active && u.UserName == item.loginName && s.Status == active
        //                                 select s.Id).FirstOrDefault();
        //                if (studentId > 0)
        //                {
        //                    foreach (var lesson in item.emeIds)
        //                    {
        //                        var emeId = lesson.ToInt();
        //                        var bookRecord = (from b in edb.BookRecord
        //                                          join s in edb.Student on b.StudentId equals s.Id
        //                                          join ar in edb.ArrangeCourse on b.ArrangeCourseId equals ar.Id
        //                                          join p in edb.ProductLevelCourseTypeCourse on ar.ProductLevelCourseTypeCourseId equals p.Id
        //                                          where b.StudentId == studentId && p.CourseId == emeId
        //                                          select b).FirstOrDefault();
        //                        bookRecord.IsSyncNotice = true;
        //                    }
        //                }
        //            }
        //            edb.SaveChanges();
        //        }
        //        catch (Exception ex)
        //        {
        //            result.Code = "EME0302";
        //            result.Message = "database excetion"+ex.ToString();
        //        }
        //    }
        //    return result;
        //}
        /// <summary>
        /// 作者:Raymond
        /// 日期:2014.10.8
        /// 描述:更新学员订课信息到爽哥
        /// </summary>
        /// <param name="userBookRecordList"></param>
        /// <returns></returns>
        public static ESBResult UpdateStudentBookRecordIsSync(List<PreviewModel> userBookRecordList)
        {
            var result = new ESBResult { Code = "000000", Message = "success" };
            int active = ConvertEnum.StatusTypeForActive;
            if (null == userBookRecordList || !userBookRecordList.Any())
            {
                result.Code = "EME0301";
                result.Message = "json data param error";
                return result;
            }
            using (var edb = new EmeEntities())
            {
                try
                {
                    foreach (var item in userBookRecordList)
                    {

                        //var userBookRecord = JsonHelper.FromJson<LessonNoticeModel>(item);
                        //var userName = userBookRecord.loginName;
                        //var lessonIds = userBookRecord.lessons;
                        var userName = item.loginName;
                        var lessonIds = item.emeIds;
                        var studentId = (from s in edb.Student
                                         join u in edb.User on s.UserId equals u.Id
                                         where u.Status == active && u.UserName == userName && s.Status == active
                                         select s.Id).FirstOrDefault();
                        if (studentId > 0)
                        {
                            foreach (var lesson in lessonIds)
                            {
                                var emeId = lesson.ToInt();
                                var bookRecord = (from b in edb.BookRecord
                                                  join s in edb.Student on b.StudentId equals s.Id
                                                  join ar in edb.ArrangeCourse on b.ArrangeCourseId equals ar.Id
                                                  join p in edb.ProductLevelCourseTypeCourse on ar.ProductLevelCourseTypeCourseId equals p.Id

                                                  where b.StudentId == studentId && p.CourseId == emeId && b.IsSyncNotice == false
                                                  select b).FirstOrDefault();
                                if (bookRecord != null)
                                    bookRecord.IsSyncNotice = true;
                            }
                        }
                    }
                    edb.SaveChanges();
                }
                catch (Exception ex)
                {
                    result.Code = "EME0302";
                    result.Message = "database excetion" + ex.ToString();
                }
            }
            return result;
        }
コード例 #8
0
ファイル: CoolApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Raymond
        /// 时间:2014.10.4
        /// 描述:同步订课信息
        /// </summary>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        public string SyncLessonNotices(string jsonData)
        {
            var result = new ESBResult { Message = "success",Code="100" };

            if (string.IsNullOrWhiteSpace(jsonData))
            {
                result.Code = "101";
                result.Message = "json data param empty";
            }
            else
            {
                try
                {
                    var previewList = JsonHelper.FromJson<List<PreviewModel>>(jsonData);
                    result = StudentBLL.UpdateStudentBookRecordIsSync(previewList);
                    //result = StudentBLL.CreateSyncLessonNotices(previewList);
                }
                catch (Exception ex)
                {
                    result.Code = "103";
                    result.Message = "json param format error";
                }
            }
            return JsonHelper.ToJson(result);
        }
コード例 #9
0
ファイル: EHRApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-22
        /// 描述:同步EHR岗位
        /// </summary>
        /// <param name="jsonData">岗位Json数据</param>
        /// <returns></returns>
        public string SyncJob(string jsonData)
        {
            var result = new ESBResult();
            JobModel job = null;
            string employeeSCode = ConfigHelper.GetAppSettingValue("EmployeeSCode");

            if (string.IsNullOrWhiteSpace(employeeSCode))
            {
                result.Code = "EME0101";
                result.Message = "请在Config中配置普通员工岗位简称!";
                return JsonHelper.ToJson(result);
            }
            if (string.IsNullOrWhiteSpace(jsonData))
            {
                result.Code = "EME0101";
                result.Message = "Json数据空值错误!";
                return JsonHelper.ToJson(result);
            }
            try
            {
                job = JsonHelper.FromJson<JobModel>(jsonData);
            }
            catch (Exception ex)
            {
                result.Code = "EME0101";
                result.Message = "Json数据格式错误!";
                return JsonHelper.ToJson(result);
            }

            result = UserBLL.EditJob(job, employeeSCode);
            return JsonHelper.ToJson(result);
        }
コード例 #10
0
ファイル: EHRApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-27
        /// 描述:同步EHR岗位状态(EHR部门Id和岗位Id确认唯一岗位)
        /// </summary>
        /// <param name="jsonData">
        ///     deptId:部门Id
        ///     jobId:岗位Id
        ///     status:101正常,102无效,103删除
        /// </param>
        /// <returns></returns>
        public string SyncJobStatus(string jsonData)
        {
            var result = new ESBResult();
            JobStatus jobStatus = null;

            if (string.IsNullOrWhiteSpace(jsonData))
            {
                result.Code = "EME0101";
                result.Message = "Json数据空值错误!";
                return JsonHelper.ToJson(result);
            }
            try
            {
                jobStatus = JsonHelper.FromJson<JobStatus>(jsonData);
            }
            catch (Exception ex)
            {
                result.Code = "EME0101";
                result.Message = "Json数据格式错误!";
                return JsonHelper.ToJson(result);
            }
            result = UserBLL.UpdateJobStatus(jobStatus);
            return JsonHelper.ToJson(result);
        }
コード例 #11
0
ファイル: EHRApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-22
        /// 描述:同步EHR员工
        /// </summary>
        /// <param name="jsonEmployee">员工Json数据</param>
        /// <returns></returns>
        public string SyncEmployee(string jsonData)
        {
            var result = new ESBResult();
            EmployeeModel employee = null;
            string ltSCode = ConfigHelper.GetAppSettingValue("LTSCode");
            string ftSCode = ConfigHelper.GetAppSettingValue("FTSCode");
            string saSCode = ConfigHelper.GetAppSettingValue("SASCode");
            string employeeSCode = ConfigHelper.GetAppSettingValue("EmployeeSCode");
            int headBranchId = ConfigHelper.GetAppSettingValue("HQBranchId").ToInt(12);

            if (string.IsNullOrWhiteSpace(ltSCode) || string.IsNullOrWhiteSpace(ftSCode) || string.IsNullOrWhiteSpace(saSCode))
            {
                result.Code = "EME103";
                result.Message = "请在Config中配置中教、外教、学习指导岗位简称!";
                return JsonHelper.ToJson(result);
            }
            try
            {
                employee = JsonHelper.FromJson<EmployeeModel>(jsonData);
            }
            catch (Exception ex)
            {
                result.Code = "EME0101";
                result.Message = "Json数据格式错误!";
                return JsonHelper.ToJson(result);
            }

            result = UserBLL.EditEmployee(employee, ltSCode, ftSCode, saSCode, headBranchId, employeeSCode);
            return JsonHelper.ToJson(result);
        }
コード例 #12
0
ファイル: EHRApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-27
        /// 描述:同步EHR员工状态
        /// </summary>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        public string SyncEmployeeStatus(string jsonData)
        {
            var result = new ESBResult();
            string ltSCode = ConfigHelper.GetAppSettingValue("LTSCode");
            string ftSCode = ConfigHelper.GetAppSettingValue("FTSCode");
            string saSCode = ConfigHelper.GetAppSettingValue("SASCode");
            EmployeeStatus employeeStatus = null;

            if (string.IsNullOrWhiteSpace(ltSCode) || string.IsNullOrWhiteSpace(ftSCode) || string.IsNullOrWhiteSpace(saSCode))
            {
                result.Code = "EME103";
                result.Message = "请在Config中配置中教、外教、学习指导岗位简称!";
                return JsonHelper.ToJson(result);
            }
            try
            {
                employeeStatus = JsonHelper.FromJson<EmployeeStatus>(jsonData);
            }
            catch (Exception ex)
            {
                result.Code = "EME0101";
                result.Message = "Json数据格式错误!";
                return JsonHelper.ToJson(result);
            }
            result = UserBLL.UpdateEmployeeStatus(employeeStatus, ltSCode, ftSCode, saSCode);
            return JsonHelper.ToJson(result);
        }
コード例 #13
0
ファイル: BranchBLL.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-08-23
        /// 描述:同步EHR部门
        /// 更新:Ark 2014-08-27 修改时不修改父
        /// </summary>
        /// <param name="dept">部门</param>
        /// <returns></returns>
        public static ESBResult EditBranch(DeptModel dept)
        {
            var result = new ESBResult { Code = "000000", Message = "成功" };
            var editUserId = -111;

            try
            {
                using (var edb = new EmeEntities())
                {
                    var remark = dept.DeptId.ToString();
                    // EHR的部门Id对应Branch的Remark

                    // 是否新增
                    bool isAdd = false;
                    var branch = edb.Branch.FirstOrDefault(b => b.Remark == remark);

                    if (null == branch)
                    {
                        isAdd = true;
                        branch = new Branch();
                    }
                    branch.DataCenterId = dept.DeptId;
                    //branch.BranchType = ESBConvert.ToBranchType(dept.NodeType, dept.NodeCode, dept.CName);
                    branch.BranchType = ESBConvert.ToBranchType(dept.NodeType);         //sap接口,只根据nodetype判断
                    branch.CName = dept.CName;
                    branch.EName = dept.EName;
                    branch.Description = dept.EName;
                    branch.Status = dept.Status;
                    branch.Remark = remark;

                    if (1 < dept.DeptId)
                    {
                        var pDeptId = dept.ParentId.ToString();

                        if (!string.IsNullOrWhiteSpace(pDeptId) && branch.BranchType != ConvertEnum.BranchTypeForHeadquarters)
                        {
                            // 查询上级部门是否存在
                            int parentId = edb.Branch.Where(b => b.Remark == pDeptId).Select(b => b.Id).FirstOrDefault();

                            if (parentId == 0)
                            {
                                result.Code = "EME0101";
                                result.Message = "请先同步上级部门!";
                                return result;
                            }

                            branch.ParentId = parentId;
                        }
                    }
                    // 不存在新增,存在修改
                    if (isAdd)
                    {
                        branch.CreateBy = editUserId;
                        branch.CreateTime = DateTime.Now;
                        edb.Branch.Add(branch);
                    }
                    else
                    {
                        branch.UpdateBy = editUserId;
                        branch.UpdateTime = DateTime.Now;
                    }

                    edb.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // 异常日志消息队列
                QueueManager.AddExceptionLog(new ExceptionLogs()
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("BranchBLL-EditBranch:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                    IsTreat = false,
                    CreateBy = -1,
                    CreateTime = DateTime.Now
                });

                result.Code = "EME0102";
                result.Message = "数据库操作异常,请联系管理员!Cause:" + ex.Message;
            }

            return result;
        }
コード例 #14
0
ファイル: StudentBLL.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014-09-17
        /// 描述:更新User同步状态为true(测评)
        /// </summary>
        /// <param name="userNameList">登录名列表</param>
        /// <returns></returns>
        public static ESBResult UpdateUserIsSync(List<string> userNameList)
        {
            var result = new ESBResult { Code = "000000" };

            try
            {
                using (var edb = new EmeEntities())
                {
                    var userList = edb.User.Where(t => userNameList.Contains(t.UserName));

                    foreach (var user in userList)
                    {
                        user.IsSync = true;
                    }

                    edb.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // 异常日志消息队列
                QueueManager.AddExceptionLog(new ExceptionLogs()
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("StudentBLL-UpdateUserIsSync:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                    IsTreat = false,
                    CreateBy = -1,
                    CreateTime = DateTime.Now
                });

                result.Code = "EME0402";
                result.Message = "database excetion"; ;
            }

            return result;
        }
コード例 #15
0
ファイル: CoolApi.cs プロジェクト: kylin589/EmePro
        /// <summary>
        /// 作者:Ark
        /// 时间:2014.09.18
        /// 描述:更新同步成功的学员权限状态
        /// </summary>
        /// <param name="userNames"></param>
        /// <returns></returns>
        public string SyncAuths(string loginNames)
        {
            var result = new ESBResult { Code = "000000" };

            if (string.IsNullOrWhiteSpace(loginNames))
            {
                result.Code = "EME0301";
                result.Message = "loginnames json empty";
            }
            else
            {
                try
                {
                    var userNameList = JsonHelper.FromJson<List<string>>(loginNames);
                    result = StudentBLL.UpdateCoolAuthIsSync(userNameList);
                }
                catch (Exception ex)
                {
                    result.Code = "EME0301";
                    result.Message = "loginnames json format error";
                }
            }

            return JsonHelper.ToJson(result);
        }
コード例 #16
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        private static Job EditJob(JobModel jobModel, string defaultSCode, EmeEntities edb)
        {
            var result = new ESBResult { Code = "000000", Message = "成功" };
            var editUserId = -111;
            using (var tran = new TransactionScope())
            {
                try
                {
                    // 查询岗位所在的部门
                    var remark = jobModel.DeptId.ToString();
                    int branchId = edb.Branch.Where(b => b.Remark == remark).Select(b => b.Id).FirstOrDefault();

                    if (branchId == 0)
                    {
                        result.Code = "EME0101";
                        result.Message = "请先同步此岗位所在的部门!";
                        return null;
                    }

                    // 是否新增(EHR部门Id和岗位Id确认唯一岗位)
                    bool isAdd = false;
                    var sCode = ESBConvert.ToSCode(jobModel.CName, jobModel.NodeCode);
                    var job = edb.Job.FirstOrDefault(b => b.BranchId == branchId && b.HrId == jobModel.JobId);

                    if (null == job)
                    {
                        isAdd = true;
                        job = new Job();
                    }

                    job.BranchId = branchId;
                    job.CName = jobModel.CName;
                    job.EName = jobModel.EName;
                    job.SCode = sCode;
                    job.IsSystem = false;
                    job.Status = jobModel.Status;

                    // 不存在新增,存在修改
                    if (isAdd)
                    {
                        job.HrId = jobModel.JobId;
                        job.Remark = "EHR同步";
                        job.CreateBy = editUserId;
                        job.CreateTime = DateTime.Now;
                        edb.Job.Add(job);
                    }
                    else
                    {
                        job.UpdateBy = editUserId;
                        job.UpdateTime = DateTime.Now;
                    }

                    edb.SaveChanges();

                    // 根据岗位简称查询角色,找不到用默认的
                    var roleId = edb.Role.Where(r => r.SCode == sCode).Select(r => r.Id).FirstOrDefault();

                    if (roleId == 0)
                    {
                        roleId = edb.Role.Where(r => r.SCode == defaultSCode).Select(r => r.Id).FirstOrDefault();
                    }

                    // 查询岗位角色关系,不存在新增,存在修改
                    var jobRole = edb.JobRoles.FirstOrDefault(jr => jr.JobId == job.Id);

                    if (null == jobRole)
                    {
                        jobRole = new JobRoles
                        {
                            JobId = job.Id,
                            RoleId = roleId,
                            Status = ConvertEnum.StatusTypeForActive,
                            CreateBy = editUserId,
                            CreateTime = DateTime.Now,
                            Remark = "EHR同步"
                        };
                        edb.JobRoles.Add(jobRole);
                    }
                    else
                    {
                        jobRole.RoleId = roleId;
                        jobRole.UpdateBy = editUserId;
                        jobRole.UpdateTime = DateTime.Now;
                    }

                    edb.SaveChanges();
                    tran.Complete();

                    return job;
                }
                catch (Exception ex)
                {
                    tran.Dispose();
                    // 异常日志消息队列
                    QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                        Message = string.Format("UserBLL-EditJob:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                        IsTreat = false,
                        CreateBy = -1,
                        CreateTime = DateTime.Now
                    });

                    result.Code = "EME0102";
                    result.Message = "数据库操作异常,请联系管理员!";
                    return null;
                }

            }
        }
コード例 #17
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        /// <summary> 
        /// 作者:Ark
        /// 时间:2014-08-27
        /// 描述:同步EHR岗位状态(EHR部门Id和岗位Id确认唯一岗位)
        /// History: sap更新同步
        /// </summary>
        /// <param name="jobStatus"></param>
        /// <returns></returns>
        public static ESBResult UpdateJobStatus(JobStatus jobStatus)
        {
            var result = new ESBResult { Code = "000000", Message = "成功" };
            var editUserId = -111;

            using (var edb = new EmeEntities())
            {
                try
                {
                    //var remark = jobStatus.DeptId.ToString();
                    //int branchId = edb.Branch.Where(b => b.Remark == remark).Select(b => b.Id).FirstOrDefault();

                    //if (branchId == 0)
                    //{
                    //    result.Code = "EME0101";
                    //    result.Message = "请先同步此岗位所在的部门!";
                    //    return result;
                    //}

                    // EHR的岗位Id对应Job的V3JobId
                    //var job = edb.Job.FirstOrDefault(b => b.BranchId == branchId && b.HrId == jobStatus.JobId);
                    var job = edb.Job.FirstOrDefault(b => b.HrId == jobStatus.JobId);

                    if (null == job)
                    {
                        result.Code = "EME0101";
                        result.Message = "操作失败,岗位Id不存在!";
                        return result;
                    }

                    job.Status = jobStatus.Status;
                    job.UpdateBy = editUserId;
                    job.UpdateTime = DateTime.Now;

                    edb.Entry(job).State = EntityState.Modified;
                    var jobRoleList = edb.JobRoles.Where(r => r.JobId == job.Id);

                    foreach (var jobRole in jobRoleList)
                    {
                        jobRole.Status = jobStatus.Status;
                        jobRole.UpdateBy = editUserId;
                        jobRole.UpdateTime = DateTime.Now;
                        edb.Entry(jobRole).State = EntityState.Modified;
                    }

                    edb.SaveChanges();
                }
                catch (Exception ex)
                {
                    // 异常日志消息队列
                    QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                        Message = string.Format("UserBLL-UpdateJobStatus:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                        IsTreat = false,
                        CreateBy = -1,
                        CreateTime = DateTime.Now
                    });

                    result.Code = "EME0102";
                    result.Message = "数据库操作异常,请联系管理员!";
                }
            }

            return result;
        }
コード例 #18
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        /// <summary> 
        /// 作者:Ark
        /// 时间:2014-08-27
        /// 描述:同步EHR员工状态(User、UserInfo、UserBranch、UserJob、Teacher、TeachRange)
        /// </summary>
        /// <param name="employeeStatus"></param>
        /// <param name="ltSCode">中教岗位简称</param>
        /// <param name="ftSCode">外教岗位简称</param>
        /// <param name="saSCode">学习指导岗位简称</param>
        /// <returns></returns>
        public static ESBResult UpdateEmployeeStatus(EmployeeStatus employeeStatus, string ltSCode, string ftSCode, string saSCode)
        {
            var result = new ESBResult { Code = "000000", Message = "成功" };
            var editUserId = -111;

            using (var edb = new EmeEntities())
            {
                try
                {
                    // EHR的岗位Id对应Job的V3JobId
                    var user = edb.User.FirstOrDefault(b => b.UserName == employeeStatus.UserName);

                    if (null == user)
                    {
                        result.Code = "EME0101";
                        result.Message = "操作失败,用户号[userName="******"]不存在!";
                        return result;
                    }
                    //取消ehr禁用员工同步到eme raymond 2014-11-03
                    if (employeeStatus.Status != 101)
                    {
                        result.Message = "禁用删除不同步到EME!";
                        return result;
                    }
                    user.Status = employeeStatus.Status;
                    user.UpdateBy = editUserId;
                    user.UpdateTime = DateTime.Now;

                    var userInfo = edb.UserInfo.FirstOrDefault(u => u.UserId == user.Id);
                    if (null != userInfo)
                    {
                        userInfo.Status = employeeStatus.Status;
                        userInfo.UpdateBy = editUserId;
                        userInfo.UpdateTime = DateTime.Now;
                    }

                    var userBranch = edb.UserBranch.FirstOrDefault(b => b.UserId == user.Id && b.IsMain);
                    if (null != userBranch)
                    {
                        userBranch.Status = employeeStatus.Status;
                        userBranch.UpdateBy = editUserId;
                        userBranch.UpdateTime = DateTime.Now;
                    }

                    var userJob = edb.UserJob.FirstOrDefault(u => u.UserId == user.Id);
                    if (null != userJob)
                    {
                        userJob.Status = employeeStatus.Status;
                        userJob.UpdateBy = editUserId;
                        userJob.UpdateTime = DateTime.Now;
                    }

                    // SA LT FT
                    var job = edb.Job.FirstOrDefault(j => j.Id == userJob.JobId);
                    if (null != job)
                    {
                        if (job.SCode == ltSCode || job.SCode == ftSCode || job.SCode == saSCode)
                        {
                            var teacher = edb.Teacher.FirstOrDefault(t => t.UserId == user.Id);
                            if (null != teacher)
                            {
                                teacher.Status = employeeStatus.Status;
                                teacher.UpdateBy = editUserId;
                                teacher.UpdateTime = DateTime.Now;

                                var teachRanges = edb.TeachRange.Where(t => t.TeacherId == teacher.Id).ToList();

                                foreach (var teachRange in teachRanges)
                                {
                                    teachRange.Status = employeeStatus.Status;
                                    teachRange.UpdateBy = editUserId;
                                    teachRange.UpdateTime = DateTime.Now;
                                }
                            }
                        }
                    }

                    edb.SaveChanges();
                }
                catch (Exception ex)
                {
                    // 异常日志消息队列
                    QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                        Message = string.Format("UserBLL-UpdateEmployeeStatus:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                        IsTreat = false,
                        CreateBy = -1,
                        CreateTime = DateTime.Now
                    });

                    result.Code = "EME0102";
                    result.Message = "数据库操作异常,请联系管理员!";
                }
            }

            return result;
        }
コード例 #19
0
ファイル: UserBLL.cs プロジェクト: kylin589/EmePro
        public static ESBResult EditEmployee(EmployeeModel employee, string ltSCode, string ftSCode, string saSCode, int headBranchId, string jobScode)
        {
            var result = new ESBResult { Code = "000000", Message = "成功" };
            var editUserId = -111;

            if (string.IsNullOrWhiteSpace(employee.UserName))
            {
                result.Code = "EME0101";
                result.Message = "同步失败,员工的[UserName]为NULL!";
                return result;
            }

            using (var edb = new EmeEntities())
            {
                using (var tran = new TransactionScope())
                {
                    try
                    {
                        // 查询员工的部门
                        var remark = employee.DeptId.ToString();
                        var branchId = headBranchId; // 默认总部

                        var centerOrHead = edb.Branch.FirstOrDefault(b => b.Remark == remark);

                        if (null == centerOrHead)
                        {
                            result.Code = "EME0101";
                            result.Message = "请先同步此员工所在的部门!";
                            return result;
                            //先新增部门
                        }
                        #region 职务(岗位)同步
                        // 查询员工的岗位
                        var job = edb.Job.FirstOrDefault(j => j.BranchId == centerOrHead.Id && j.HrId == employee.JobId);
                        if (null == job)
                        {

                            //先新增岗位
                            var jobModel = new JobModel
                            {
                                JobId = employee.JobId,
                                DeptId = employee.DeptId,
                                CName = employee.JobName,
                                Status = ConvertEnum.StatusTypeForActive,
                                EName = employee.JobName,
                                NodeCode = jobScode
                            };
                            job = EditJob(jobModel, jobScode, edb);
                            if (job == null)
                            {
                                result.Code = "EME0101";
                                result.Message = "职务同步失败!";
                                return result;
                            }
                        }
                        #endregion

                        while (centerOrHead.BranchType != ConvertEnum.BranchTypeForSchool && centerOrHead.BranchType != ConvertEnum.BranchTypeForArea && centerOrHead.BranchType != ConvertEnum.BranchTypeForCompany)
                        {
                            if (null == centerOrHead)
                                break;

                            centerOrHead = edb.Branch.FirstOrDefault(b => b.Id == centerOrHead.ParentId);
                        }
                        if (null != centerOrHead)
                        {
                            if (centerOrHead.BranchType == ConvertEnum.BranchTypeForSchool)
                                branchId = centerOrHead.Id;
                            else if (centerOrHead.BranchType == ConvertEnum.BranchTypeForArea)
                                branchId = centerOrHead.Id;
                        }

                        // 员工类型默认员工
                        var userType = ConvertEnum.UserTypeForEmployee;
                        var status = ConvertEnum.StatusTypeForActive;
                        var jobStatusType = ESBConvert.ToJobStatusType(employee.JobStatus);

                        if (job.SCode == ltSCode || job.SCode == ftSCode)
                            userType = ConvertEnum.UserTypeForTeacher;
                        if (jobStatusType == ConvertEnum.JobStatusTypeForLeave)
                            status = ConvertEnum.StatusTypeForInactive;

                        #region 同步员工基本信息(User、UserInfo、UserBranch、UserJob)

                        #region User

                        // 是否新增
                        var isAddUser = false;
                        //根据老用户名称是否存在 2014-11-4 raymond 修改
                        var userName = string.IsNullOrEmpty(employee.OldName) ? employee.UserName : employee.OldName;
                        var user = edb.User.FirstOrDefault(u => u.UserName == userName);
                        //var user = edb.User.FirstOrDefault(u => u.UserName == employee.OldName);

                        if (null == user)
                        {
                            isAddUser = true;
                            user = new User();
                        }

                        user.UserType = userType;
                        user.Status = status;
                        user.Email = employee.Email;
                        user.Mobile = employee.Mobile;
                        user.Remark = "修改前" + employee.OldName;
                        // 不存在新增,存在修改
                        if (isAddUser)
                        {
                            user.UserName = employee.UserName;
                            user.Password = "******";
                            user.Remark = "EHR同步";
                            user.CreateBy = editUserId;
                            user.CreateTime = employee.CreateTime;
                            edb.User.Add(user);
                            edb.SaveChanges();
                        }
                        else
                        {
                            user.IsSync = false;
                            user.UpdateBy = editUserId;
                            user.UpdateTime = DateTime.Now;
                        }

                        #endregion
                        #region UserInfo

                        // 是否新增
                        var isAddUserInfo = false;
                        var userInfo = edb.UserInfo.FirstOrDefault(u => u.UserId == user.Id);

                        if (null == userInfo)
                        {
                            isAddUserInfo = true;
                            userInfo = new UserInfo();
                        }

                        userInfo.UserId = user.Id;
                        userInfo.EName = employee.EName;
                        userInfo.CName = employee.CName;
                        userInfo.Sex = ESBConvert.ToSex(employee.Sex);
                        userInfo.Email = employee.Email;
                        userInfo.Mobile = employee.Mobile;
                        userInfo.Birthday = employee.Birthday;
                        userInfo.JobStatusType = jobStatusType;
                        userInfo.Status = status;

                        if (isAddUserInfo)
                        {
                            userInfo.Remark = "EHR同步";
                            userInfo.CreateBy = editUserId;
                            userInfo.CreateTime = employee.CreateTime;
                            edb.UserInfo.Add(userInfo);
                        }
                        else
                        {
                            userInfo.UpdateBy = editUserId;
                            userInfo.UpdateTime = DateTime.Now;
                        }

                        #endregion
                        #region UserBranch

                        // 是否新增
                        var isAddUserBranch = false;
                        var userBranch = edb.UserBranch.FirstOrDefault(b => b.UserId == user.Id/* && b.BranchId == branchId*/ && b.IsMain);

                        if (null == userBranch)
                        {
                            isAddUserBranch = true;
                            userBranch = new UserBranch();
                        }

                        userBranch.UserId = user.Id;
                        userBranch.BranchId = branchId;
                        userBranch.Status = status;
                        userBranch.IsMain = true;

                        if (isAddUserBranch)
                        {
                            userBranch.Remark = "EHR同步";
                            userBranch.CreateBy = editUserId;
                            userBranch.CreateTime = employee.CreateTime;
                            edb.UserBranch.Add(userBranch);
                        }
                        else
                        {
                            userBranch.UpdateBy = editUserId;
                            userBranch.UpdateTime = DateTime.Now;
                        }

                        #endregion
                        #region UserJob

                        // 是否新增
                        var isAddUserJob = false;
                        var userJobList = edb.UserJob.Where(u => u.UserId == user.Id).ToList();
                        var activeCount = userJobList.Count(u => u.Status == ConvertEnum.StatusTypeForActive);
                        var userJob = userJobList.FirstOrDefault(u => u.JobId == job.Id);

                        // 如果userJob数量=1,直接修改此userJob
                        if (activeCount == 1)
                        {
                            userJob = userJobList.FirstOrDefault(u => u.Status == ConvertEnum.StatusTypeForActive);
                        }

                        if (null == userJob)
                        {
                            isAddUserJob = true;
                            userJob = new UserJob();
                        }

                        userJob.JobId = job.Id;
                        userJob.Status = status;

                        if (isAddUserJob)
                        {
                            userJob.UserId = user.Id;
                            userJob.Remark = "EHR同步";
                            userJob.CreateBy = editUserId;
                            userJob.CreateTime = employee.CreateTime;
                            edb.UserJob.Add(userJob);
                        }
                        else
                        {
                            userJob.UpdateBy = editUserId;
                            userJob.UpdateTime = DateTime.Now;
                        }

                        #endregion

                        edb.SaveChanges();

                        #endregion

                        #region 同步老师(Teacher、TeachRange)

                        // 教师和学习指导同步到Teacher、TeachRange
                        if (job.SCode == ltSCode || job.SCode == ftSCode || job.SCode == saSCode)
                        {
                            var teacherType = ConvertEnum.TeacherTypeForSA;

                            if (job.SCode == ltSCode)
                                teacherType = ConvertEnum.TeacherTypeForLT;
                            if (job.SCode == ftSCode)
                                teacherType = ConvertEnum.TeacherTypeForFT;

                            // 是否新增
                            var isAddTeacher = false;
                            var teacher = edb.Teacher.FirstOrDefault(t => t.UserId == user.Id);

                            if (null == teacher)
                            {
                                isAddTeacher = true;
                                teacher = new Teacher();
                            }

                            teacher.UserId = user.Id;
                            teacher.TeacherType = teacherType;
                            teacher.Status = status;
                            teacher.IsFullTime = true;
                            var flag = true; //默认添加 TeachRange

                            if (isAddTeacher)
                            {
                                teacher.Remark = "EHR同步";
                                teacher.CreateBy = editUserId;
                                teacher.CreateTime = DateTime.Now;
                                edb.Teacher.Add(teacher);
                                edb.SaveChanges();
                            }
                            else
                            {
                                teacher.UpdateBy = editUserId;
                                teacher.UpdateTime = DateTime.Now;
                                flag = !edb.TeachRange.Any(t => t.TeacherId == teacher.Id);
                            }
                            if (flag)
                            {
                                // 最近的同级的范围
                                var newSameLvelTeacherId = (from t in edb.Teacher
                                                            join r in edb.TeachRange on t.Id equals r.TeacherId
                                                            where t.TeacherType == teacherType && t.Status == ConvertEnum.StatusTypeForActive
                                                            orderby t.Id descending
                                                            select t.Id).Take(1).FirstOrDefault();

                                if (newSameLvelTeacherId > 0)
                                {
                                    var rangeList = edb.TeachRange.Where(t => t.TeacherId == newSameLvelTeacherId && t.Status == ConvertEnum.StatusTypeForActive).ToList();

                                    foreach (var range in rangeList)
                                    {
                                        var teachRange = new TeachRange
                                        {
                                            TeacherId = teacher.Id,
                                            ProductLevelId = range.ProductLevelId,
                                            Status = status,
                                            CreateBy = editUserId,
                                            CreateTime = DateTime.Now
                                        };
                                        edb.TeachRange.Add(teachRange);
                                    }
                                }
                            }

                            edb.SaveChanges();
                        }

                        #endregion

                        tran.Complete();
                    }
                    catch (Exception ex)
                    {
                        tran.Dispose();
                        // 异常日志消息队列
                        QueueManager.AddExceptionLog(new ExceptionLogs()
                        {
                            ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                            Message = string.Format("UserBLL-EditEmployee:{0};{1};{2}", ex.Message, ex.InnerException.Message, ex.HelpLink),
                            IsTreat = false,
                            CreateBy = -1,
                            CreateTime = DateTime.Now
                        });

                        result.Code = "EME0102";
                        result.Message = "数据库操作异常,请联系管理员!Cause:" + ex.Message;
                    }
                }
            }

            return result;
        }