diff --git a/APT.BaseData.Domain/IServices/FM/IFMUserService.cs b/APT.BaseData.Domain/IServices/FM/IFMUserService.cs index 4bb102f..a6ae0dc 100644 --- a/APT.BaseData.Domain/IServices/FM/IFMUserService.cs +++ b/APT.BaseData.Domain/IServices/FM/IFMUserService.cs @@ -4,6 +4,8 @@ using APT.BaseData.Domain.Entities.FM; using System; using System.Collections.Generic; using APT.Infrastructure.Api; +using APT.BaseData.Domain.Entities.OP; + namespace APT.BaseData.Domain.IServices.FM { /// @@ -111,5 +113,28 @@ namespace APT.BaseData.Domain.IServices.FM /// 1 /// T_FM_USER GetSafeApproveUser(Guid ORG_ID, int UserType = 1); + + /// + /// 人员注册 方法统一 + /// 扫码注册提取 + /// + /// + /// + /// 如果没有 取 Phone + /// + /// + /// + /// + /// + /// + /// + /// this.Request.Headers["Tenant"] + /// + /// + /// + /// 是否默认角色 或者 原有方式 + /// + /// 200 正常 500 方法自己做提示 + int RegisterUser(string Name, string Phone, string Code, int Sex, string ID_CARD, DateTime InTime, int WORKINGYEAR, Guid ORG_ID, Guid? DEPARTMENT_ID, Guid? POST_ID, string TENANT, ref T_OP_ALLUSER alluser, ref T_FM_PERSON newPerson, ref T_FM_USER newUser, ref List listRole, ref string Msg); } } diff --git a/APT.BaseData.Services/Services/FM/FMUserService.cs b/APT.BaseData.Services/Services/FM/FMUserService.cs index e43afe6..73c9c62 100644 --- a/APT.BaseData.Services/Services/FM/FMUserService.cs +++ b/APT.BaseData.Services/Services/FM/FMUserService.cs @@ -14,6 +14,7 @@ using APT.Infrastructure.Api; using APT.MS.Domain.Entities.PF; using APT.BaseData.Domain.Dtos; using Castle.Core.Internal; +using APT.BaseData.Domain.Entities.OP; namespace APT.BaseData.Services.Services.FM { @@ -1021,5 +1022,137 @@ namespace APT.BaseData.Services.Services.FM } #endregion + + /// + /// 人员注册 方法统一 + /// 扫码注册提取 + /// + /// + /// + /// 如果没有 取 Phone + /// + /// + /// + /// + /// + /// + /// + /// this.Request.Headers["Tenant"] + /// + /// + /// + /// 是否默认角色 或者 原有方式 + /// + /// 200 正常 500 方法自己做提示 + public int RegisterUser(string Name, string Phone, string Code, int Sex, string ID_CARD, DateTime InTime, int WORKINGYEAR, Guid ORG_ID, Guid? DEPARTMENT_ID, Guid? POST_ID, string TENANT, ref T_OP_ALLUSER alluser, ref T_FM_PERSON newPerson, ref T_FM_USER newUser, ref List listRole, ref string Msg) + { + if (Name == null || Phone == null) + { + Msg = "请填写信息!"; + return 500; + } + if (ORG_ID == Guid.Empty) + { + Msg = "获取公司信息失败!"; + return 500; + } + if (DEPARTMENT_ID == null || DEPARTMENT_ID.Value == Guid.Empty) + { + Msg = "请选择入职组织!"; + return 500; + } + var isrepeat = GetEntity(t => t.CODE == Phone); + if (isrepeat != null) + { + Msg = "该账户已注册!"; + return 500; + } + + if (string.IsNullOrEmpty(Code)) + { + Code = Phone; + } + + newPerson = new T_FM_PERSON(); + newPerson.ID = Guid.NewGuid(); + newPerson.CODE = Phone; + newPerson.NAME = Name; + newPerson.SEX = Sex; + newPerson.TEL = Phone; + newPerson.ORG_ID = ORG_ID; + newPerson.DEPARTMENT_ID = DEPARTMENT_ID; + if (POST_ID.HasValue && POST_ID.Value != Guid.Empty) + { + newPerson.POST_ID = POST_ID; + } + + newUser = new T_FM_USER(); + newUser.ID = Guid.NewGuid(); + newUser.CODE = Phone; + newUser.NAME = Name; + newUser.SEX = Sex; + newUser.PHONE = Phone; + newUser.ID_CARD = ID_CARD; + newUser.ENTRYTIME = InTime; + newUser.WORKINGYEAR = WORKINGYEAR; + newUser.PERSON_ID = newPerson.ID; + newUser.PASSWORD = "E10ADC3949BA59ABBE56E057F20F883E"; + newUser.ORG_ID = ORG_ID; + newUser.DEPARTMENT_ID = DEPARTMENT_ID; + newUser.NUM = 1000;//按 NUM 排序 靠后 + //newUser.ENABLE_STATUS = 1;//先配置不可用 三级安全教育完成后 再启用 + + //T_SE_USER_TEMP newTemp = new T_SE_USER_TEMP(); + //newTemp.ID = Guid.NewGuid(); + //newTemp.USER_ID = newUser.ID; + //newTemp.ORG_ID = ORG_ID; + + var listDefault = GetEntities(e => e.ISDEFAULT && !e.IS_DELETED); + listRole = new List(); + if (listDefault != null && listDefault.Count() > 0) + { + T_FM_USER_BELONG_ROLE modelRole = null; + foreach (var item in listDefault) + { + modelRole = new T_FM_USER_BELONG_ROLE(); + modelRole.USER_ID = newUser.ID; + modelRole.BELONG_ROLE_ID = item.ID; + modelRole.ORG_ID = ORG_ID; + listRole.Add(modelRole); + } + } + else + { + var role1 = this.GetEntity(t => t.NAME == "APP用户"); + var role2 = this.GetEntity(t => t.NAME == "作业员"); + T_FM_USER_BELONG_ROLE belongRole1 = null; + T_FM_USER_BELONG_ROLE belongRole2 = null; + if (role1 != null) + { + belongRole1 = new T_FM_USER_BELONG_ROLE(); + belongRole1.USER_ID = newUser.ID; + belongRole1.BELONG_ROLE_ID = role1.ID; + belongRole1.ORG_ID = ORG_ID; + listRole.Add(belongRole1); + } + if (role2 != null) + { + belongRole2 = new T_FM_USER_BELONG_ROLE(); + belongRole2.USER_ID = newUser.ID; + belongRole2.BELONG_ROLE_ID = role2.ID; + belongRole2.ORG_ID = ORG_ID; + listRole.Add(belongRole2); + } + } + + alluser = new T_OP_ALLUSER(); + alluser.CODE = Phone; + alluser.TENANT = TENANT; + alluser.ORG_ID = ORG_ID; + alluser.PHONE = Phone; + + Msg = ""; + return 200; + } } } diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs index 6d39a99..ff25da6 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIHeadSEController.cs @@ -193,8 +193,9 @@ namespace APT.SC.WebApi.Controllers.Api.BI { ID = new Guid(item[0].ToString()), TITLE = item[1].ToString(), - CREATE_TIME = Convert.ToDateTime(item[2].ToString()) - }); ; + CREATE_TIME = Convert.ToDateTime(item[2].ToString()), + START = Convert.ToDateTime(item["START"].ToString()) + }); } catch { } diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/H5Controller.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/H5Controller.cs index 4e491e2..760efa2 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/H5Controller.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/H5Controller.cs @@ -200,24 +200,45 @@ namespace APT.SC.WebApi.Controllers.Api.BI newTemp.ID = Guid.NewGuid(); newTemp.USER_ID = newUser.ID; newTemp.ORG_ID = orgId; - var role1 = this.GetEntity(t => t.NAME == "APP用户"); - var role2 = this.GetEntity(t => t.NAME == "作业员"); - T_FM_USER_BELONG_ROLE belongRole1 = null; - T_FM_USER_BELONG_ROLE belongRole2 = null; - if (role1 != null) + + var listDefault = GetEntities(e => e.ISDEFAULT && !e.IS_DELETED, null, null); + List listRole = new List(); + if (listDefault != null && listDefault.Count() > 0) { - belongRole1 = new T_FM_USER_BELONG_ROLE(); - belongRole1.USER_ID = newUser.ID; - belongRole1.BELONG_ROLE_ID = role1.ID; - belongRole1.ORG_ID = orgId; + T_FM_USER_BELONG_ROLE modelRole = null; + foreach (var item in listDefault) + { + modelRole = new T_FM_USER_BELONG_ROLE(); + modelRole.USER_ID = newUser.ID; + modelRole.BELONG_ROLE_ID = item.ID; + modelRole.ORG_ID = orgId; + listRole.Add(modelRole); + } } - if (role2 != null) + else { - belongRole2 = new T_FM_USER_BELONG_ROLE(); - belongRole2.USER_ID = newUser.ID; - belongRole2.BELONG_ROLE_ID = role2.ID; - belongRole2.ORG_ID = orgId; + var role1 = this.GetEntity(t => t.NAME == "APP用户"); + var role2 = this.GetEntity(t => t.NAME == "作业员"); + T_FM_USER_BELONG_ROLE belongRole1 = null; + T_FM_USER_BELONG_ROLE belongRole2 = null; + if (role1 != null) + { + belongRole1 = new T_FM_USER_BELONG_ROLE(); + belongRole1.USER_ID = newUser.ID; + belongRole1.BELONG_ROLE_ID = role1.ID; + belongRole1.ORG_ID = orgId; + listRole.Add(belongRole1); + } + if (role2 != null) + { + belongRole2 = new T_FM_USER_BELONG_ROLE(); + belongRole2.USER_ID = newUser.ID; + belongRole2.BELONG_ROLE_ID = role2.ID; + belongRole2.ORG_ID = orgId; + listRole.Add(belongRole2); + } } + using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"])) { T_OP_ALLUSER alluser = new T_OP_ALLUSER(); @@ -234,10 +255,12 @@ namespace APT.SC.WebApi.Controllers.Api.BI AddEntityNoCommit(newUser); if (newPerson != null) AddEntityNoCommit(newPerson); - if (belongRole1 != null) - AddEntityNoCommit(belongRole1); - if (belongRole2 != null) - AddEntityNoCommit(belongRole2); + //if (belongRole1 != null) + // AddEntityNoCommit(belongRole1); + //if (belongRole2 != null) + // AddEntityNoCommit(belongRole2); + if (listRole != null && listRole.Count() > 0) + BantchSaveEntityNoCommit(listRole); if (newTemp != null) AddEntityNoCommit(newTemp); }); diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs index 19818aa..bc4d614 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs @@ -41,6 +41,8 @@ namespace APT.SC.WebApi.Controllers.Api.SE { return SafeExecute(() => { + + List sendNoticeList = new List(); List detailFiles = new List(); T_FM_NOTIFICATION_TASK finishNotice = null; @@ -76,18 +78,22 @@ namespace APT.SC.WebApi.Controllers.Api.SE //var listCode = Nav_NewUserDetail.Where(e => e.CODE.Length > 0).Select(e => e.CODE); //var listUserCheck = GetEntities(e => listCode.Contains(e.CODE), null, null); - var listCode = Nav_NewUserDetail.Where(e => e.CODE != null).Where(e => e.CODE.Length > 0).Select(e => e.CODE); - IEnumerable listUserCheck = null; - if (listCode != null && listCode.Count() > 0) - { - listUserCheck = GetEntities(e => listCode.Contains(e.CODE), null, null); - } + //var listCode = Nav_NewUserDetail.Where(e => e.CODE != null).Where(e => e.CODE.Length > 0).Select(e => e.CODE); + //IEnumerable listUserCheck = null; + //if (listCode != null && listCode.Count() > 0) + //{ + // listUserCheck = GetEntities(e => listCode.Contains(e.CODE), null, null); + //} #region NEXT_DEPARTMENT_ID 系统按规律给下级组织 自己可修改下级组织 int index = 0; foreach (var item in Nav_NewUserDetail) { + if (item.IS_DELETED) + { + continue; + } index++; if (!item.NEXT_DEPARTMENT_ID.HasValue || entity.TRAIN_STATUS == SEThreeLevelSafeTrainType.班组级) { @@ -108,103 +114,113 @@ namespace APT.SC.WebApi.Controllers.Api.SE item.Nav_DepartmentNext = null; } - //foreach (var item in Nav_NewUserDetail) - //{ - // var dep = alldeps.FirstOrDefault(t => t.ID == item.USER_DEPARTMENT_ID); - // //if (dep.DEPARTMENT_TYPE == auditDep.DEPARTMENT_TYPE)//登录者的层级 等于 新用户的层级 - // if (dep.DEPARTMENT_TYPE <= auditDep.DEPARTMENT_TYPE)//登录者的层级 小于 新用户的层级 - // { - // if (string.IsNullOrEmpty(item.CODE)) - // { - // throw new Exception("请填写行:" + (index + 1) + "的工号!"); - // } - // if (item.USER_POST_ID == Guid.Empty || item.USER_POST_ID == null) - // { - // throw new Exception("请填写行:" + (index + 1) + "的岗位!"); - // } - // } - // if (listUserCheck != null && listUserCheck.Count() > 0 && !string.IsNullOrEmpty(item.CODE) && item.USER_ID.HasValue) - // { - // var CodeCheck = listUserCheck.FirstOrDefault(e => e.CODE == item.CODE && e.ID != item.USER_ID); - // if (CodeCheck != null) - // { - // throw new Exception("工号不能重复【" + item.CODE + "】!"); - // } - // } - // index++; - //} - //if (entity.TRAIN_STATUS == SEThreeLevelSafeTrainType.公司级) - //{ - // foreach (var item in Nav_NewUserDetail) - // { - // /// 部门层级 FMDepartmentType 公司=5 部门=10, 车间=15, 班组=20, - // /// FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3 - // var dep = alldeps.FirstOrDefault(t => t.ID == item.USER_DEPARTMENT_ID); - // if (dep.DEPARTMENT_TYPE == 10) - // { - // item.NEXT_DEPARTMENT_ID = dep.ID; - // } - // if (dep.DEPARTMENT_TYPE == 15) - // { - // item.NEXT_DEPARTMENT_ID = dep.Nav_Parent.ID; - // } - // else if (dep.DEPARTMENT_TYPE == 20) - // { - // item.NEXT_DEPARTMENT_ID = dep.Nav_Parent.Nav_Parent.ID; - // } - // } - //} - //if (entity.TRAIN_STATUS == SEThreeLevelSafeTrainType.部门级) - //{ - // foreach (var item in Nav_NewUserDetail) - // { - // item.NEXT_DEPARTMENT_ID = item.USER_DEPARTMENT_ID; - // } - //} - #endregion var allDepartment = Nav_NewUserDetail.Where(t => t.IS_DELETED == false).Select(t => t.USER_DEPARTMENT_ID); - var allUser = GetEntities(t => allDepartment.Contains(t.DEPARTMENT_ID) && t.Nav_ApproveRole != null, new BaseFilter(entity.ORG_ID)); - index = 1; - if (entity.IS_CREATETEST == SETrainNeedSuvey.否) + if (allDepartment == null || allDepartment.Count() < 1) { + //全部都删除了 + entity.IS_DELETED = true; foreach (var item in Nav_NewUserDetail) { - if (string.IsNullOrEmpty(item.SCORE)) - { - throw new Exception("线下考试请填写分数,行【" + index + "】!"); - } - if (!item.EXAMINATION_RESULTS.HasValue) - { - throw new Exception("线下考试请完善考核结果,行【" + index + "】!"); - } - if (item.Nav_Files == null) - { - throw new Exception("线下考试请上传附件,行【" + index + "】!"); - } - if (item.Nav_Files != null && item.Nav_Files.Count() > 0) - { - item.Nav_Files.ForEach(nf => - { - nf.USER_DETAIL_ID = item.ID; - }); - detailFiles.AddRange(item.Nav_Files); - item.Nav_Files = null; - } - index++; + item.IS_DELETED = true; + } + foreach (var item in Nav_Teachers) + { + item.IS_DELETED = true; + } + foreach (var item in Nav_Files) + { + item.IS_DELETED = true; + } + foreach (var item in detailFiles) + { + item.IS_DELETED = true; } } - var listUserID = Nav_NewUserDetail.Where(e => e.USER_ID.HasValue).Select(e => e.USER_ID.Value); - var listUser = GetEntities(e => listUserID.Contains(e.ID), null); - - foreach (var item in Nav_NewUserDetail) + else { - if (!item.USER_ID.HasValue) - continue; - sendNoticeList.Add(NotificationTaskService.InsertUserNoticeTaskModel("三级安全培训记录-" + entity.TRAIN_STATUS.GetDescription() + "-签到", item.ID, entity.ORG_ID, (Guid)item.USER_ID, listUser.FirstOrDefault(e => e.ID == item.USER_ID.Value)?.NAME, DateTime.Now, DateTime.Now.AddDays(1), 1, "SE062_SHOWPRINT")); + var allUser = GetEntities(t => allDepartment.Contains(t.DEPARTMENT_ID) && t.Nav_ApproveRole != null, new BaseFilter(entity.ORG_ID)); + index = 1; + if (entity.IS_CREATETEST == SETrainNeedSuvey.否) + { + foreach (var item in Nav_NewUserDetail) + { + if (string.IsNullOrEmpty(item.SCORE)) + { + throw new Exception("线下考试请填写分数,行【" + index + "】!"); + } + if (!item.EXAMINATION_RESULTS.HasValue) + { + throw new Exception("线下考试请完善考核结果,行【" + index + "】!"); + } + if (item.Nav_Files == null) + { + throw new Exception("线下考试请上传附件,行【" + index + "】!"); + } + if (item.Nav_Files != null && item.Nav_Files.Count() > 0) + { + item.Nav_Files.ForEach(nf => + { + nf.USER_DETAIL_ID = item.ID; + }); + detailFiles.AddRange(item.Nav_Files); + item.Nav_Files = null; + } + index++; + } + } + var listUserID = Nav_NewUserDetail.Where(e => e.USER_ID.HasValue).Select(e => e.USER_ID.Value); + var listUser = GetEntities(e => listUserID.Contains(e.ID), null); + + foreach (var item in Nav_NewUserDetail) + { + if (!item.USER_ID.HasValue || item.IS_DELETED) + continue; + sendNoticeList.Add(NotificationTaskService.InsertUserNoticeTaskModel("三级安全培训记录-" + entity.TRAIN_STATUS.GetDescription() + "-签到", item.ID, entity.ORG_ID, (Guid)item.USER_ID, listUser.FirstOrDefault(e => e.ID == item.USER_ID.Value)?.NAME, DateTime.Now, DateTime.Now.AddDays(1), 1, "SE062_SHOWPRINT")); + } } finishNotice = NotificationTaskService.GetTaskFinishModel(entity.TaskID, "SE061_SHOWPRINT"); } + + var deleteD = Nav_NewUserDetail.Where(e => e.IS_DELETED && e.USER_ID.HasValue); + List listUserDel = null; + List listPersonDel = null; + List listRoleDel = null; + IEnumerable listUT = null; + + if (deleteD != null && deleteD.Count() > 0) + { + var listUserIDDel = deleteD.Select(e => e.USER_ID.Value); + var listUsers = GetEntities(e => listUserIDDel.Contains(e.ID), null, "Nav_Person", "Nav_BelongRoles"); + listUT = GetEntities(e => e.USER_ID.HasValue && listUserIDDel.Contains(e.USER_ID.Value), null, null); + listUserDel = new List(); + listPersonDel = new List(); + listRoleDel = new List(); + + foreach (var item in listUsers) + { + item.Nav_Person.IS_DELETED = true; + item.Nav_Person.MODIFY_TIME = DateTime.Now; + listPersonDel.Add(item.Nav_Person); + if (item.Nav_BelongRoles != null && item.Nav_BelongRoles.Any()) + { + foreach (var itemr in item.Nav_BelongRoles) + { + itemr.IS_DELETED = true; + itemr.MODIFY_TIME = DateTime.Now; + } + listRoleDel.AddRange(item.Nav_BelongRoles); + } + item.Nav_BelongRoles = null; + item.Nav_Person = null; + item.IS_DELETED = true; + item.MODIFY_TIME = DateTime.Now; + listUserDel.Add(item); + } + } + + + UnifiedCommit(() => { UpdateEntityNoCommit(entity); @@ -213,15 +229,38 @@ namespace APT.SC.WebApi.Controllers.Api.SE if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (Nav_NewUserDetail != null && Nav_NewUserDetail.Any()) - BantchSaveEntityNoCommit(Nav_NewUserDetail); + BantchUpdateEntity_noneBase(Nav_NewUserDetail);//BantchSaveEntityNoCommit(Nav_NewUserDetail); if (Nav_Files != null && Nav_Files.Any()) - BantchSaveEntityNoCommit(Nav_Files); + BantchUpdateEntity_noneBase(Nav_Files);//BantchSaveEntityNoCommit if (detailFiles.Any()) - BantchSaveEntityNoCommit(detailFiles); + BantchUpdateEntity_noneBase(detailFiles);//BantchSaveEntityNoCommit if (Nav_Teachers.Any()) - BantchSaveEntityNoCommit(Nav_Teachers); + BantchUpdateEntity_noneBase(Nav_Teachers);//BantchSaveEntityNoCommit + if (listUserDel != null && listUserDel.Any()) + BantchUpdateEntity_noneBase(listUserDel); + if (listPersonDel != null && listPersonDel.Any()) + BantchUpdateEntity_noneBase(listPersonDel); + if (listRoleDel != null && listRoleDel.Any()) + BantchUpdateEntity_noneBase(listRoleDel); + if (listUT != null && listUT.Any()) + BantchUpdateEntity_noneBase(listUT); }); + if (listUserDel != null && listUserDel.Count() > 0) + { + var listCode = listUserDel.Select(e => e.CODE); + using (var context = new MigrationContext()) + { + var listDel = context.GetEntities(e => listCode.Contains(e.CODE) && e.ORG_ID == entity.ORG_ID, null, null); + foreach (var item in listDel) + { + item.IS_DELETED = true; + } + context.DeleteEntities(listDel); + context.SaveChanges(); + } + } + return true; }); } @@ -1247,5 +1286,139 @@ namespace APT.SC.WebApi.Controllers.Api.SE return GetEntities(null, filter).Select(it => it.Nav_User).Distinct(it => it.ID).ToList(); }); } + + #region 新增人员 + + /// + /// 注册用户 + /// + /// 分页过滤实体 + /// + [HttpPost, Route("RegisterUser")] + public JsonActionResult RegisterUser([FromBody] RegisterUserModel model) + { + return SafeExecute(() => + { + if (model.EDU_CARD_ID == Guid.Empty) + { + throw new Exception("传参有误,获取三级安全教育表单ID失败,请刷新后再试!"); + } + T_FM_PERSON newPerson = null; + T_FM_USER newUser = null; + List listRole = null; + T_OP_ALLUSER alluser = null; + string Msg = String.Empty; + int code = UserService.RegisterUser(model.Name, model.Phone, model.Code, model.Sex, model.ID_CARD, model.InTime, model.WORKINGYEAR, model.ORG_ID, model.DEPARTMENT_ID, model.POST_ID, this.Request.Headers["Tenant"], ref alluser, ref newPerson, ref newUser, ref listRole, ref Msg); + if (code != 200) + { + throw new Exception(Msg); + } + + T_SE_USER_TEMP newTemp = new T_SE_USER_TEMP(); + newTemp.ID = Guid.NewGuid(); + newTemp.USER_ID = newUser.ID; + newTemp.ORG_ID = model.ORG_ID; + + T_SE_NEW_USER_DETAIL userDetail = new T_SE_NEW_USER_DETAIL(); + userDetail.ID = Guid.NewGuid(); + userDetail.EDU_CARD_ID = model.EDU_CARD_ID; + userDetail.USER_ID = newUser.ID; + userDetail.ID_CARD_NUMBER = newUser.ID_CARD; + userDetail.STATUS = 0; + userDetail.ORG_ID = newUser.ORG_ID; + userDetail.IN_TIME = newUser.ENTRYTIME; + userDetail.USER_DEPARTMENT_ID = newUser.DEPARTMENT_ID; + userDetail.USER_POST_ID = model.POST_ID; + + #region NEXT_DEPARTMENT_ID //默认到对应部门 给矿山 选矿 否则给 安环 + + if (newUser.DEPARTMENT_ID.HasValue) + { + var listDeps = GetEntities(e => e.ENABLE_STATUS == 0 && !e.IS_DELETED, null); + var modelDep = listDeps.FirstOrDefault(e => e.ID == newUser.DEPARTMENT_ID.Value); + if (modelDep.DEPARTMENT_TYPE == 5) + { + //公司领导 + } + else if (modelDep.DEPARTMENT_TYPE == 10) + { + //部门人员 + if (modelDep.DEPARTMENT_STATUS == 1)//FMDepartmentStatus 职能部门 = 0, 生产部门 = 1, 安全部门 = 2, + { + userDetail.NEXT_DEPARTMENT_ID = modelDep.ID; + } + else + { + modelDep = listDeps.FirstOrDefault(e => e.DEPARTMENT_STATUS == 2); + if (modelDep != null) + { + userDetail.NEXT_DEPARTMENT_ID = modelDep.ID; + } + } + } + else if (modelDep.DEPARTMENT_TYPE == 15) + { + userDetail.NEXT_DEPARTMENT_ID = modelDep.PARENT_ID;//给组织对应上级组织 + } + else if (modelDep.DEPARTMENT_TYPE == 20) + { + //班主 对应组织 的父级的父级 + if (modelDep.PARENT_ID.HasValue) + { + modelDep = listDeps.FirstOrDefault(e => e.ID == modelDep.PARENT_ID.Value); + } + if (modelDep != null) + { + userDetail.NEXT_DEPARTMENT_ID = modelDep.PARENT_ID; + } + } + } + + #endregion + + using (var context = new MigrationContext()) + { + context.AddEntity(alluser); + context.SaveChanges(); + } + + UnifiedCommit(() => + { + if (newUser != null) + AddEntityNoCommit(newUser); + if (newPerson != null) + AddEntityNoCommit(newPerson); + if (userDetail != null) + AddEntityNoCommit(userDetail); + if (listRole != null && listRole.Count() > 0) + BantchSaveEntityNoCommit(listRole); + if (newTemp != null) + AddEntityNoCommit(newTemp); + }); + + return GetEntity(e => e.ID == userDetail.ID, "Nav_Department", "Nav_Post", "Nav_User", "Nav_DepartmentNext"); + }); + } + + #endregion + + } + + public class RegisterUserModel + { + public string Name { get; set; } + public int Sex { get; set; } + public string Phone { get; set; } + /// + /// 没值取 Phone + /// + public string Code { get; set; } + public string ID_CARD { get; set; } + public DateTime InTime { get; set; } + public int WORKINGYEAR { get; set; } + public Guid ORG_ID { get; set; } + public Guid? DEPARTMENT_ID { get; set; } + public Guid? POST_ID { get; set; } + public Guid EDU_CARD_ID { get; set; } } }