/// <summary> /// 新建员工 /// </summary> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddYJEmployeeExt(Jinher.AMP.BTP.Deploy.YJEmployeeDTO input) { try { Guid UserId = CBCSV.GetUserIdByAccount(input.UserAccount); //if (UserId == Guid.Empty || UserId == null) //{ // return new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = "该用户不是易捷用户!" }; //} var UserInfo = YJEmployee.ObjectSet().FirstOrDefault(p => (p.UserAccount == input.UserAccount || p.IdentityNum == input.IdentityNum) && p.AppId == p.AppId && p.IsDel == 0); if (UserInfo != null) { return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = "该用户已存在!" }); } ContextSession contextSession = ContextFactory.CurrentThreadContext; YJEmployee YJEmp = YJEmployee.CreateYJEmployee(); YJEmp.UserId = UserId; YJEmp.UserCode = input.UserCode; YJEmp.UserAccount = input.UserAccount; YJEmp.UserName = input.UserName; YJEmp.IdentityNum = input.IdentityNum; YJEmp.Phone = input.Phone; YJEmp.Area = input.Area; YJEmp.StationCode = input.StationCode; YJEmp.StationName = input.StationName; YJEmp.IsDel = 0; YJEmp.SubId = ContextDTO.LoginUserID; YJEmp.SubOn = DateTime.Now; YJEmp.AppId = input.AppId; YJEmp.IsManager = input.IsManager; if (YJEmp.IsManager == 1) { YJEmp.Department = input.Department; YJEmp.Station = input.Station; } else { YJEmp.Department = ""; YJEmp.Station = ""; } contextSession.SaveObject(YJEmp); contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("YJEmployeeBP.AddYJEmployeeExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true, Message = "添加成功" }); }
/// <summary> /// 导入员工信息 /// </summary> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.YJEmployeeSearchDTO> ImportYJEmployeeListExt(System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.YJEmployeeDTO> YJEmpList, System.Guid AppId) { try { ContextSession contextSession = ContextFactory.CurrentThreadContext; YJEmployeeSearchDTO YJEmpl = new YJEmployeeSearchDTO(); var YJEmpListNoRepeat = YJEmpList.GroupBy(P => P.UserAccount).Select(P => P.FirstOrDefault()).ToList(); var IcardList = YJEmpList.Select(s => s.IdentityNum).ToList(); //身份证号 List <string> UserAccountList = YJEmpListNoRepeat.Select(S => S.UserAccount).ToList(); //用户账号 //验证重复账号 var ExistIcardDate = YJEmployee.ObjectSet().Where(p => IcardList.Contains(p.IdentityNum) && p.IsDel == 0 && p.AppId == AppId).Select(s => s.IdentityNum).ToList(); var ExistDate = YJEmployee.ObjectSet().Where(p => UserAccountList.Contains(p.UserAccount) && p.IsDel == 0 && p.AppId == AppId).ToList(); var RepeatData = ExistDate.Select(s => s.UserAccount).ToList(); YJEmpl.RepeatData = YJEmpListNoRepeat.Where(p => RepeatData.Contains(p.UserAccount)).ToList(); YJEmpl.RepeatIcardData = YJEmpList.Where(p => ExistIcardDate.Contains(p.IdentityNum)).ToList(); if (YJEmpl.RepeatIcardData.Any()) { return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.YJEmployeeSearchDTO> { Data = YJEmpl, ResultCode = 1, isSuccess = false, Message = "数据库中已存在,请核对后再导入~" }); } //取出无效数据 List <string> Invalid = new List <string>(); foreach (var item in YJEmpListNoRepeat) { Guid UserId = CBCSV.GetUserIdByAccount(item.UserAccount); item.UserId = UserId; if (UserId == Guid.Empty || UserId == null) { Invalid.Add(item.UserAccount); } } YJEmpl.InvalidData = YJEmpListNoRepeat.Where(p => Invalid.Contains(p.UserAccount)).Select(s => s.UserAccount).ToList(); foreach (var item in YJEmpListNoRepeat) { var ExistEmpolyee = ExistDate.FirstOrDefault(p => p.UserAccount == item.UserAccount); if (ExistEmpolyee == null) { YJEmployee YJEmp = YJEmployee.CreateYJEmployee(); YJEmp.UserId = item.UserId; YJEmp.UserCode = item.UserCode; YJEmp.UserAccount = item.UserAccount; YJEmp.UserName = item.UserName; YJEmp.IdentityNum = item.IdentityNum; YJEmp.Phone = item.Phone; YJEmp.Area = item.Area; YJEmp.StationCode = item.StationCode; YJEmp.StationName = item.StationName; YJEmp.IsDel = 0; YJEmp.SubId = ContextDTO.LoginUserID; YJEmp.SubOn = DateTime.Now; YJEmp.AppId = item.AppId; YJEmp.IsManager = item.IsManager; YJEmp.Department = item.Department; YJEmp.Station = item.Station; contextSession.SaveObject(YJEmp); } else { ExistEmpolyee.UserId = item.UserId; ExistEmpolyee.UserCode = item.UserCode; ExistEmpolyee.UserAccount = item.UserAccount; ExistEmpolyee.UserName = item.UserName; ExistEmpolyee.IdentityNum = item.IdentityNum; ExistEmpolyee.Phone = item.Phone; ExistEmpolyee.Area = item.Area; ExistEmpolyee.StationCode = item.StationCode; ExistEmpolyee.StationName = item.StationName; ExistEmpolyee.IsDel = 0; ExistEmpolyee.SubId = ContextDTO.LoginUserID; ExistEmpolyee.SubOn = DateTime.Now; ExistEmpolyee.AppId = item.AppId; ExistEmpolyee.IsManager = item.IsManager; ExistEmpolyee.Department = item.Department; ExistEmpolyee.Station = item.Station; ExistEmpolyee.EntityState = EntityState.Modified; contextSession.SaveObject(ExistEmpolyee); } } contextSession.SaveChanges(); return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.YJEmployeeSearchDTO> { Data = YJEmpl, ResultCode = 0, isSuccess = true, Message = "导入成功" }); } catch (Exception ex) { LogHelper.Error("YJEmployeeBP.AddYJEmployeeExt 异常", ex); return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.YJEmployeeSearchDTO> { isSuccess = false, ResultCode = 2, Message = ex.Message }); } }