示例#1
0
 public void Add(EmployeeBaseInfo entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     _employeeBaseInfoRepository.Add(entity);
 }
示例#2
0
        /// <summary>
        /// 解析员工基本信息
        /// </summary>
        private void ParseToEmployeeBaseInfo(List <string> values, ref EmployeeBaseInfo entity, ref List <ImportErrorColModel> errors)
        {
            //检查数据项
            var UserName = string.IsNullOrEmpty(values[0]) ? "" : values[0];
            var IDCard   = values[1];

            if (IDCard.Length != 18)
            {
                errors.Add(new ImportErrorColModel()
                {
                    ColIndex = 1,
                    Message  = ERROR_IDCARD,
                });
            }
            var Sex = string.IsNullOrEmpty(values[2]) ? "" : values[2];

            if (errors.Count == 0)
            {
                //开始解析
                if (string.IsNullOrEmpty(entity.IDCard))
                {
                    entity.UserName    = UserName;
                    entity.IDCard      = IDCard;
                    entity.Sex         = Sex;
                    entity.Deleted     = false;
                    entity.CreatetDate = DateTime.Now;
                    entity.CreatedBy   = _workContext.CurrentMembershipUser.Username;
                }
                else
                {
                    entity.UserName = UserName;
                    entity.Sex      = Sex;
                }
            }
            else
            {
                entity = null;
            }
        }
示例#3
0
 public void Add(EmployeeBaseInfo entity)
 {
     _context.EmployeeBaseInfo.Add(entity);
 }
示例#4
0
        public ActionResult CreateOrUpdate(CompanyEmployeeViewModel model)
        {
            ValidateCompanyEmployeeViewModel(model);

            if (ModelState.IsValid)
            {
                if (model.Id.ToString() == "00000000-0000-0000-0000-000000000000")
                {
                    using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                    {
                        //判断是否有baseinfo
                        var baseInfoEntity = _employeeBaseInfoService.GetByIdCard(model.IDCard);
                        if (baseInfoEntity == null)
                        {
                            baseInfoEntity             = new EmployeeBaseInfo();
                            baseInfoEntity.Id          = Guid.NewGuid();
                            baseInfoEntity.IDCard      = model.IDCard;
                            baseInfoEntity.Sex         = model.Sex;
                            baseInfoEntity.UserName    = model.UserName;
                            baseInfoEntity.CreatedBy   = _workContext.CurrentMembershipUser.Username;
                            baseInfoEntity.CreatetDate = DateTime.Now;
                            _employeeBaseInfoService.Add(baseInfoEntity);
                            unitOfWork.SaveChanges();
                        }
                        else//覆盖掉原来的数据,奇怪的设计
                        {
                            baseInfoEntity.Sex      = model.Sex;
                            baseInfoEntity.UserName = model.UserName;
                        }
                        var company = _companyService.GetById(model.CompanyId);
                        //职业史
                        var lastWork = baseInfoEntity.WorkHistories.OrderByDescending(x => x.EntryDate).FirstOrDefault();
                        if (lastWork == null || lastWork.EntryDate > model.StartPostDate)
                        {
                            var workHistory = new EmployeeWorkHistory
                            {
                                WorkType         = model.WorkType,
                                Department       = model.Department,
                                EntryDate        = model.StartPostDate,
                                LeaveDate        = model.EndPostDate,
                                AdverseFactor    = model.AdverseFactor,
                                CompanyName      = company.CompanyName,
                                EmployeeBaseInfo = baseInfoEntity,
                                CreatedBy        = WorkContext.CurrentMembershipUser.Username,
                                Deleted          = false
                            };
                            _employeeWorkHistoryService.Add(workHistory);
                        }
                        if (model.EndPostDate != null)
                        {
                            if (model.LeaveDate == null)
                            {
                                model.LeaveDate = model.EndPostDate;
                            }
                            if (lastWork != null && model.StartPostDate == lastWork.EntryDate && company.CompanyName == lastWork.CompanyName && model.Department == lastWork.Department && model.WorkType == lastWork.WorkType && model.AdverseFactor == lastWork.AdverseFactor)
                            {
                                lastWork.LeaveDate = model.EndPostDate;
                            }
                        }
                        if (model.EntryDate == null)
                        {
                            model.EntryDate = model.StartPostDate;
                        }

                        //体检状态根据上岗时间及离岗时间自动生成(上岗时间在三个月内自动默认为上岗前,与数据库关联,未做岗前体检的人员超过三个月自动默认为在岗
                        if (model.EndPostDate != null)
                        {
                            model.HealthStatusId = 12;
                        }
                        else
                        {
                            if ((DateTime.Now - Convert.ToDateTime(model.StartPostDate)).Days > 90)
                            {
                                model.HealthStatusId = 11;
                            }
                            else
                            {
                                model.HealthStatusId = 13;
                            }
                        }
                        var entity = new CompanyEmployee()
                        {
                            Id               = Guid.NewGuid(),
                            AdverseMonthes   = model.AdverseMonthes,
                            TotalWorkMonthes = model.TotalWorkMonthes,
                            EntryDate        = model.EntryDate,
                            LeaveDate        = model.LeaveDate,
                            StartPostDate    = model.StartPostDate,

                            EndPostDate      = model.EndPostDate,
                            AdverseFactor    = model.AdverseFactor,
                            Comment          = model.Comment,
                            ContactPhone     = model.ContactPhone,
                            Department       = model.Department,
                            Email            = model.Email,
                            ProtectType      = model.ProtectType,
                            WorkNumber       = model.WorkNumber,
                            WorkType         = model.WorkType,
                            Company          = company,
                            HealthStatus     = _categoryService.GetById(model.HealthStatusId),
                            Married          = _categoryService.GetById(model.MarriedId),
                            MigrantWorker    = _categoryService.GetById(model.MigrantWorkerId),
                            EmployeeBaseInfo = baseInfoEntity,

                            CreatedBy   = _workContext.CurrentMembershipUser.Username,
                            CreatedDate = DateTime.Now
                        };

                        //7、总工龄企业未维护空白项的根据职业史中的入岗时间自动生成,接害工龄企业未维护的,根据职业史中危害因素为非空白的记录推算时间,如企业维护时间的按维护时间为准。
                        if (model.TotalWorkMonthes == null)
                        {
                            var earliestWorkHisotory = baseInfoEntity.WorkHistories.OrderBy(x => x.EntryDate).FirstOrDefault();
                            if (earliestWorkHisotory != null)
                            {
                                entity.TotalWorkMonthes = Math.Abs(DateTime.Now.Month - entity.StartPostDate.Value.Month) + 12 * (DateTime.Now.Year - entity.StartPostDate.Value.Year);
                            }
                        }

                        if (model.AdverseMonthes == null)
                        {
                            var workHisotries = baseInfoEntity.WorkHistories.OrderBy(x => x.EntryDate);
                            int monthes       = 0;
                            foreach (var item in workHisotries)
                            {
                                if (!string.IsNullOrEmpty(item.AdverseFactor))
                                {
                                    monthes += (Math.Abs(item.LeaveDate.Value.Month - item.EntryDate.Value.Month) + 12 * (item.LeaveDate.Value.Year - item.EntryDate.Value.Year));
                                }
                            }
                            entity.AdverseMonthes = monthes;
                        }
                        _companyEmployeeService.Add(entity);
                        unitOfWork.Commit();

                        SuccessNotification("添加成功");
                        PrepareCompanyEmployeeViewModel(model, entity);
                        return(View(model));
                    }
                }
                else
                {
                    var entity = _companyEmployeeService.GetById(model.Id);
                    if (entity != null)
                    {
                        using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                        {
                            //判断是否有baseinfo,修改状态下应该是有的
                            var baseInfoEntity = _employeeBaseInfoService.GetByIdCard(model.IDCard);
                            if (baseInfoEntity == null)
                            {
                                baseInfoEntity             = new EmployeeBaseInfo();
                                baseInfoEntity.Id          = Guid.NewGuid();
                                baseInfoEntity.IDCard      = model.IDCard;
                                baseInfoEntity.Sex         = model.Sex;
                                baseInfoEntity.UserName    = model.UserName;
                                baseInfoEntity.CreatedBy   = _workContext.CurrentMembershipUser.Username;
                                baseInfoEntity.CreatetDate = DateTime.Now;
                                _employeeBaseInfoService.Add(baseInfoEntity);
                            }
                            else//覆盖掉原来的数据,奇怪的设计
                            {
                                baseInfoEntity.Sex      = model.Sex;
                                baseInfoEntity.UserName = model.UserName;
                            }

                            entity.AdverseMonthes   = model.AdverseMonthes;
                            entity.TotalWorkMonthes = model.TotalWorkMonthes;
                            entity.EntryDate        = model.EntryDate;
                            entity.LeaveDate        = model.LeaveDate;
                            if (model.EntryDate == null)
                            {
                                entity.EntryDate = model.StartPostDate;
                            }

                            entity.StartPostDate = model.StartPostDate;
                            var company = _companyService.GetById(model.CompanyId);

                            var lastWork = baseInfoEntity.WorkHistories.OrderByDescending(x => x.EntryDate).FirstOrDefault();
                            if (lastWork == null || lastWork.EntryDate > model.StartPostDate)
                            {
                                var workHistory = new EmployeeWorkHistory
                                {
                                    WorkType         = model.WorkType,
                                    Department       = model.Department,
                                    EntryDate        = model.StartPostDate,
                                    LeaveDate        = model.EndPostDate,
                                    AdverseFactor    = model.AdverseFactor,
                                    CompanyName      = company.CompanyName,
                                    EmployeeBaseInfo = baseInfoEntity,
                                    CreatedBy        = WorkContext.CurrentMembershipUser.Username,
                                    Deleted          = false
                                };
                                _employeeWorkHistoryService.Add(workHistory);
                            }
                            if (model.EndPostDate != null)
                            {
                                if (model.LeaveDate == null)
                                {
                                    entity.LeaveDate = model.EndPostDate;
                                }


                                if (lastWork != null && model.StartPostDate == lastWork.EntryDate && entity.Company.CompanyName == lastWork.CompanyName)
                                {
                                    lastWork.LeaveDate = model.EndPostDate;
                                }
                            }
                            entity.EndPostDate = model.EndPostDate;

                            entity.AdverseFactor = model.AdverseFactor;
                            entity.Comment       = model.Comment;
                            entity.ContactPhone  = model.ContactPhone;
                            entity.Department    = model.Department;
                            entity.Email         = model.Email;
                            entity.ProtectType   = model.ProtectType;
                            entity.WorkNumber    = model.WorkNumber;
                            entity.WorkType      = model.WorkType;
                            entity.Company       = company;

                            //体检状态根据上岗时间及离岗时间自动生成(上岗时间在三个月内自动默认为上岗前,与数据库关联,未做岗前体检的人员超过三个月自动默认为在岗
                            if (entity.EndPostDate != null)
                            {
                                model.HealthStatusId = 12;
                            }
                            else
                            {
                                if ((DateTime.Now - Convert.ToDateTime(model.StartPostDate)).Days > 90)
                                {
                                    model.HealthStatusId = 11;
                                }
                                else
                                {
                                    model.HealthStatusId = 13;
                                }
                            }

                            entity.HealthStatus     = _categoryService.GetById(model.HealthStatusId);
                            entity.Married          = _categoryService.GetById(model.MarriedId);
                            entity.MigrantWorker    = _categoryService.GetById(model.MigrantWorkerId);
                            entity.EmployeeBaseInfo = baseInfoEntity;

                            entity.UpdatedBy   = _workContext.CurrentMembershipUser.Username;
                            entity.UpdatedDate = DateTime.Now;

                            unitOfWork.Commit();

                            SuccessNotification("编辑成功");
                            PrepareCompanyEmployeeViewModel(model, entity);
                            return(View(model));
                        }
                    }
                    else
                    {
                        ErrorNotification(new Exception("编辑失败,未找到Id为" + model.Id.ToString() + "的员工"));
                        return(RedirectToAction("Index"));
                    }
                }
            }
            else
            {
                ErrorNotification(new Exception("编辑失败,输入信息有误"));
                PrepareCompanyEmployeeViewModel(model, null);
                return(View(model));
            }
        }
示例#5
0
        //解析成员工信息,并更新或插入
        private void ParseToEntity(List <string> values, ref List <ImportErrorColModel> errors, bool isCoverData)
        {
            //判断源数据是否有身份证号
            if (!string.IsNullOrEmpty(values[1]))
            {
                //判断是否有EmployeeBaseInfo
                var baseInfo = _employeeBaseInfoRepository.GetByIDCard(values[1]);
                if (baseInfo == null)
                {
                    baseInfo = new EmployeeBaseInfo();
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);

                        if (baseInfo != null)
                        {
                            _employeeBaseInfoRepository.Add(baseInfo);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                //_currentUserCompany = _companyService.GetById(_workContext.CurrentMembershipUser.Companies.FirstOrDefault(x => x.IsDefault == true).Id);
                _currentUserCompany = _companyService.GetById(_workContext.CurrentMembershipUser.Company.Id);
                //这里有问题,应先获取公司,再从公司获取员工
                var entity = _companyEmployeeRepository.GetEmployee(baseInfo.IDCard, _currentUserCompany.Id);
                //创建新员工
                if (entity == null)
                {
                    entity = new CompanyEmployee();
                    try
                    {
                        entity.EmployeeBaseInfo = baseInfo;
                        ParseToCompanyEmployee(values, ref entity, errors);
                        if (entity != null)
                        {
                            //是否覆盖
                            if (isCoverData)
                            {
                                _companyEmployeeRepository.DeleteByCompanyID(entity.Company.Id);
                            }
                            entity.EmployeeBaseInfo = baseInfo;
                            _companyEmployeeRepository.Add(entity);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        entity.EmployeeBaseInfo = baseInfo;
                        ParseToCompanyEmployee(values, ref entity, errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            else
            {
                //没有身份证号
                errors.Add(new ImportErrorColModel()
                {
                    ColIndex = 2,
                    Message  = ERROR_IDCARD_EMPTY,
                });
                //继续查看是否有其他错误
                var entity = new CompanyEmployee();
                try
                {
                    ParseToCompanyEmployee(values, ref entity, errors);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
示例#6
0
        //解析成员工信息,并更新或插入
        private void ParseToEntity(List <string> values, ref List <ImportErrorColModel> errors, bool isCoverData)
        {
            //判断源数据是否有身份证号
            if (!string.IsNullOrEmpty(values[1]))
            {
                //判断是否有EmployeeBaseInfo
                var baseInfo = _employeeBaseInfoRepository.GetByIDCard(values[1]);
                if (baseInfo == null)
                {
                    baseInfo = new EmployeeBaseInfo();
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);
                        if (baseInfo != null)
                        {
                            _employeeBaseInfoRepository.Add(baseInfo);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        ParseToEmployeeBaseInfo(values, ref baseInfo, ref errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }

                var entity = _employeeWorkHistoryRepository.GetByIDCard(values[1]);
                //创建新员工
                if (entity == null)
                {
                    entity = new EmployeeWorkHistory();
                    try
                    {
                        ParseToEmployeeWorkHistory(values, ref entity, ref errors);
                        if (entity != null)
                        {
                            entity.EmployeeBaseInfo = baseInfo;
                            _employeeWorkHistoryRepository.Add(entity);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    try
                    {
                        ParseToEmployeeWorkHistory(values, ref entity, ref errors);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            else
            {
                //没有身份证号
                errors.Add(new ImportErrorColModel()
                {
                    ColIndex = 2,
                    Message  = ERROR_IDCARD_EMPTY,
                });
                //继续查看是否有其他错误
                var entity = new EmployeeWorkHistory();
                try
                {
                    ParseToEmployeeWorkHistory(values, ref entity, ref errors);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }