using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Entities.OP; using APT.BaseData.Domain.Enums; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices; using APT.BaseData.Domain.IServices.FM; using APT.BaseData.Services.Services.FM; using APT.Infrastructure.Api; using APT.Infrastructure.Core; using APT.Migrations; using APT.MS.Domain.Entities.FO; using APT.MS.Domain.Entities.LR; using APT.MS.Domain.Entities.SE; using APT.MS.Domain.Entities.WB; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Mvc; using Microsoft.CodeAnalysis; using NPOI.SS.Formula.Functions; namespace APT.SC.WebApi.Controllers.Api.WB { [Route("api/WB/WBRegister")] public class WBRegisterController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } IPFApproveCallBackService ApproveCallBackService { get; set; } IFMFlowPermitService MFlowPermitService { get; set; } public WBRegisterController(IFMNotificationTaskService notificationTaskService, IPFApproveCallBackService approveCallBackService, IFMFlowPermitService mFlowPermitService) { NotificationTaskService = notificationTaskService; ApproveCallBackService = approveCallBackService; MFlowPermitService = mFlowPermitService; } /// /// 保存 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_WB_REGISTER entity) { return SafeExecute(() => { //wyw 修改 人员信息 已经提出单独页面处理 此处不处理 List file1 = new List(); //List file21 = new List(); //List file22 = new List(); //List file23 = new List(); //List file24 = new List(); List file3 = new List(); List file4 = new List(); //List newPersons = new List(); //List newUsers = new List(); //T_FM_USER_PRODUCTION_UNIT unit = null; //List productionUnit = null; //List belongRole1s = new List(); //List belongRole2s = new List(); T_FM_NOTIFICATION_TASK sendNotice = null; T_FM_NOTIFICATION_TASK finishNotice = null; var project = GetEntity(t => t.ID == entity.PROJECT_ID); var item1 = entity.Nav_Item1; var item2 = entity.Nav_Item2; var item3 = entity.Nav_Item3; var item4 = entity.Nav_Item4; DateTime dtNow = DateTime.Now; //暂不必填 //if (item4 == null || item4.Count() < 1) //{ // throw new Exception("外包单位必须要有【设备设施】!"); //} entity.Nav_Item1.ForEach(t => { if (t.Nav_Files != null && t.Nav_Files.Count() > 0) { file1.AddRange(t.Nav_Files); t.Nav_Files = null; } }); //entity.Nav_Item2.ForEach(t => //{ // if (t.Nav_Files1 != null && t.Nav_Files1.Count() > 0) // { // file21.AddRange(t.Nav_Files1); // t.Nav_Files1 = null; // } // if (t.Nav_Files2 != null && t.Nav_Files2.Count() > 0) // { // file22.AddRange(t.Nav_Files2); // t.Nav_Files2 = null; // } // if (t.Nav_Files3 != null && t.Nav_Files3.Count() > 0) // { // file23.AddRange(t.Nav_Files3); // t.Nav_Files3 = null; // } // if (t.Nav_Files4 != null && t.Nav_Files4.Count() > 0) // { // file24.AddRange(t.Nav_Files4); // t.Nav_Files4 = null; // } //}); entity.Nav_Item3.ForEach(t => { if (t.Nav_Files != null && t.Nav_Files.Count() > 0) { file3.AddRange(t.Nav_Files); t.Nav_Files = null; } }); entity.Nav_Item4.ForEach(t => { if (t.Nav_Files != null && t.Nav_Files.Count() > 0) { file4.AddRange(t.Nav_Files); t.Nav_Files = null; } }); entity.Nav_Item1 = null; entity.Nav_Item2 = null; entity.Nav_Item3 = null; entity.Nav_Item4 = null; //foreach (var it2 in item2) //{ // it2.AGE = CalculateAgeFromIDCard(it2.ID_CARD); //} List iListUser = null; string CALLBACK_INTERFACE = string.Empty; T_PF_APPROVE approve = null; List listApproveDetail = null; List listDATA_ID = new List(); if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (item1.Count() == 0) { throw new Exception("安全生产管理协议不能为空!"); } else { foreach (var item in item1) { if (item.END_TIME.HasValue && item.END_TIME.Value <= dtNow) { throw new Exception("安全生产管理协议结束时间必须大于今天!"); } } } if (item2.Count() == 0) { throw new Exception("人员信息不能为空!"); } if (item3 != null && item3.Any()) { foreach (var item in item3) { if (item.VALID_TIME.HasValue && item.VALID_TIME.Value <= dtNow) { throw new Exception("资质证书有效期必须大于今天!"); } } } T_WB_REGISTER_4_FILE modelFileCheck = null; if (item4 != null && item4.Any()) { foreach (var item in item4) { if (item.IS_SPECIAL_DEVICE) { modelFileCheck = file4.FirstOrDefault(e => e.PARENT_ID == item.ID); if (modelFileCheck == null) { throw new Exception("特种设备【" + item.NAME + "】必须上传检测报告!"); } else if (!item.DATE_LIMIT.HasValue) { throw new Exception("【" + item.NAME + "】报告有效期限必填!"); } } } } //if (entity.STATUS != PFStandardStatus.Archived)//如果都是已归档数据 那么只做信息修改 比如状态启用禁用 不走流程 //{ entity.STATUS = PFStandardStatus.Approving; #region // wyw 代码已抽离 并且此代码有bug //foreach (var user in item2) //{ // if (user.IS_LOGIN) // { // var isrepeat = GetEntity(t => t.CODE == user.PHONE); // if (isrepeat == null && user.IS_LOGIN) // { // T_FM_USER newUser = new T_FM_USER(); // T_FM_PERSON newPerson = new T_FM_PERSON(); // newPerson.ID = Guid.NewGuid(); // newPerson.CODE = user.PHONE; // newPerson.NAME = user.NAME; // newPerson.SEX = 0; // newPerson.TEL = user.PHONE; // newPerson.ORG_ID = entity.ORG_ID; // newUser.ID = Guid.NewGuid(); // newUser.CODE = user.PHONE; // newUser.NAME = user.NAME; // newUser.SEX = 0; // newUser.PHONE = user.PHONE; // newUser.ENTRYTIME = DateTime.Now; // newUser.PERSON_ID = newPerson.ID; // newUser.PROJECT_ID = entity.PROJECT_ID; // newUser.MineType = "_0_10_20_30_"; // newUser.ID_CARD = user.ID_CARD; // var mineTypeList = newUser.MineType.Split("_"); // unit = new T_FM_USER_PRODUCTION_UNIT(); // productionUnit = new List(); // foreach (var mineTypeItem in mineTypeList) // { // if (mineTypeItem != "") // { // var enumList = this.GetEntity(t => t.CODE == "BSMineTypeEnum" && t.VALUE == int.Parse(mineTypeItem)); // unit.ORG_ID = entity.ORG_ID; // unit.USER_ID = newUser.ID; // unit.ENUMS_ID = enumList?.ID; // unit.Nav_Enums = null; // productionUnit.Add(unit); // } // } // newUser.PASSWORD = "E10ADC3949BA59ABBE56E057F20F883E"; // newUser.ORG_ID = entity.ORG_ID; // var role1 = this.GetEntity(t => t.NAME == "APP用户"); // var role2 = this.GetEntity(t => t.NAME == "作业员"); // if (role1 != null) // { // T_FM_USER_BELONG_ROLE belongRole1 = new T_FM_USER_BELONG_ROLE(); // belongRole1.USER_ID = newUser.ID; // belongRole1.BELONG_ROLE_ID = role1.ID; // belongRole1.ORG_ID = entity.ORG_ID; // belongRole1s.Add(belongRole1); // } // if (role2 != null) // { // T_FM_USER_BELONG_ROLE belongRole2 = new T_FM_USER_BELONG_ROLE(); // belongRole2.USER_ID = newUser.ID; // belongRole2.BELONG_ROLE_ID = role2.ID; // belongRole2.ORG_ID = entity.ORG_ID; // belongRole2s.Add(belongRole2); // } // newUsers.Add(newUser); // newPersons.Add(newPerson); // var Tenant = this.Request.Headers["Tenant"]; // using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"])) // { // T_OP_ALLUSER alluser = new T_OP_ALLUSER(); // alluser.CODE = user.PHONE; // alluser.TENANT = Tenant; // alluser.ORG_ID = entity.ORG_ID; // alluser.PHONE = user.PHONE; // context.AddEntity(alluser); // context.SaveChanges(); // } // } // } //} #endregion //sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("外包单位信息登记表审批", entity.ID, entity.ORG_ID, project.USER_ID, GetEntity(project.USER_ID).NAME, DateTime.Now, DateTime.Now.AddDays(7), 1, "WB004_SHOWPRINT"); //if (entity.TaskID != Guid.Empty) //{ // finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID, "WB004_SHOWPRINT"); //} Dictionary dicApproveUser = new Dictionary(); //dicApproveUser.Add(1, GetEntity(project.USER_ID));//建设项目负责人 dicApproveUser.Add(1, GetEntity(project.LAUNCH_USER_ID));//外包录入人 T_FM_USER fmDep = null; if (!project.LAUNCH_DEPARTMENT_ID.HasValue) { throw new Exception("建设部门不能为空!"); } else { var modelDep = GetEntity(e => e.ID == project.LAUNCH_DEPARTMENT_ID.Value, "Nav_User"); if (modelDep != null) { if (modelDep.DEPARTMENT_TYPE == 10 || modelDep.DEPARTMENT_TYPE == 5) { fmDep = modelDep.Nav_User; } else if (modelDep.DEPARTMENT_TYPE == 15) { if (modelDep.PARENT_ID.HasValue) { modelDep = GetEntity(modelDep.PARENT_ID.Value, null, "Nav_User"); if (modelDep.Nav_User != null) { fmDep = modelDep.Nav_User; } } } else if (modelDep.DEPARTMENT_TYPE == 20) { modelDep = GetEntity(modelDep.PARENT_ID.Value, null, "Nav_Parent.Nav_User"); if (modelDep.Nav_Parent != null && modelDep.Nav_Parent.Nav_User != null) { fmDep = modelDep.Nav_Parent.Nav_User; } } } else { throw new Exception("获取建设部门信息失败!"); } if (fmDep != null) { dicApproveUser.Add(2, fmDep);//建设部门负责人 } } string Msg = ""; approve = MFlowPermitService.GetApproveInfo("WB004", null, entity.ID, "WB004_SHOWPRINT", entity.TaskID, "WB004_SHOWPRINT", null, dicApproveUser, null, "", ref Msg, ref finishNotice, ref sendNotice, ref CALLBACK_INTERFACE, ref listDATA_ID); if (Msg != null && !string.IsNullOrEmpty(Msg)) { throw new Exception(Msg);//如果有问题 进行提示 } //listApproveDetail = approve.Nav_ApproveDetails; listApproveDetail = approve.Nav_ApproveDetails.Where(e => e.APPROVE_USER_ID.HasValue && e.APPROVE_USER_ID != Guid.Empty).ToList(); approve.Nav_ApproveDetails = null; //} //启用、禁用 if (entity.ENABLE_STATUS == FMEnableStatusEnum.禁用) { iListUser = GetEntities(e => e.PROJECT_ID.HasValue && e.PROJECT_ID == entity.PROJECT_ID && e.ENABLE_STATUS == 0, null, null).ToList(); foreach (var item in iListUser) { item.ENABLE_STATUS = 1;//账号禁用 } } else { var iListUserALL = GetEntities(e => e.PROJECT_ID.HasValue && e.PROJECT_ID == entity.PROJECT_ID, null, null); var iListUser0 = iListUserALL.Where(e => e.ENABLE_STATUS == 0); if (iListUser0 == null || !iListUser0.Any()) { iListUser = new List(); //签约 但是没有一个可用账号 //全部可用 foreach (var item in iListUser) { item.ENABLE_STATUS = 0;//账号启用 iListUser.Add(item); } } } } UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (item1 != null && item1.Any()) BantchSaveEntityNoCommit(item1); if (item2 != null && item2.Any()) BantchSaveEntityNoCommit(item2); if (item3 != null && item3.Any()) BantchSaveEntityNoCommit(item3); if (item4 != null && item4.Any()) BantchSaveEntityNoCommit(item4); if (file1 != null && file1.Any()) BantchSaveEntityNoCommit(file1); //if (file21 != null && file21.Any()) // BantchSaveEntityNoCommit(file21); //if (file22 != null && file22.Any()) // BantchSaveEntityNoCommit(file22); //if (file23 != null && file23.Any()) // BantchSaveEntityNoCommit(file23); //if (file24 != null && file24.Any()) // BantchSaveEntityNoCommit(file24); if (file3 != null && file3.Any()) BantchSaveEntityNoCommit(file3); if (file4 != null && file4.Any()) BantchSaveEntityNoCommit(file4); //if (newUsers != null && newUsers.Any()) // BantchSaveEntityNoCommit(newUsers); //if (newPersons != null && newPersons.Any()) // BantchSaveEntityNoCommit(newPersons); //if (belongRole1s != null && belongRole1s.Any()) // BantchSaveEntityNoCommit(belongRole1s); //if (belongRole2s != null && belongRole2s.Any()) // BantchSaveEntityNoCommit(belongRole2s); if (sendNotice != null) AddEntityNoCommit(sendNotice); if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (iListUser != null && iListUser.Any()) BantchSaveEntityNoCommit(iListUser); if (approve != null) UpdateEntityNoCommit(approve); if (listApproveDetail != null && listApproveDetail.Any()) BantchSaveEntityNoCommit(listApproveDetail); }); //执行信息 if (!string.IsNullOrEmpty(CALLBACK_INTERFACE)) { if (CALLBACK_INTERFACE.EndsWith("New")) { this.UnifiedCommit(() => { ApproveCallBackService.CallBackNew(CALLBACK_INTERFACE, approve, false); }); } else { this.UnifiedCommit(() => { ApproveCallBackService.CallBack(CALLBACK_INTERFACE, listDATA_ID); }); } } return true; }); } /// /// 审核通过 /// /// /// [HttpPost, Route("UserAgree")] public JsonActionResult UserAgree([FromBody] T_WB_REGISTER entity) { return SafeExecute(() => { var register = GetEntity(t => t.ID == entity.ID); var project = GetEntity(t => t.ID == register.PROJECT_ID); register.STATUS = PFStandardStatus.Archived; var finishTask = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID); T_WB_TRAIN_SELECT select = new T_WB_TRAIN_SELECT(); select.ID = Guid.NewGuid(); select.ORG_ID = entity.ORG_ID; select.PROJECT_ID = register.PROJECT_ID; //人员信息修改都要走审批流 //如果有人没有分数 进行入场培训 var modelCheck = GetEntity(e => e.SCORE == 0 && e.PARENT_ID == entity.ID); T_FM_NOTIFICATION_TASK sendNotice = null; if (modelCheck != null && modelCheck.ID != Guid.Empty) { var taskCheck = GetEntity(e => e.USER_ID == project.SCENE_USER_ID && e.NOTICE_STATUS == 0 && e.SOURCE_FORMCODE == "WB006"); if (taskCheck == null || taskCheck.ID == Guid.Empty) { sendNotice = NotificationTaskService.InsertUserNoticeTaskModel(project.UNIT_NAME + "-入厂安全培训指派", select.ID, entity.ORG_ID, project.SCENE_USER_ID, GetEntity(project.SCENE_USER_ID).NAME, DateTime.Now, DateTime.Now.AddDays(7), 1, "WB006"); } } UnifiedCommit(() => { if (register != null) UpdateEntityNoCommit(register); if (sendNotice != null) AddEntityNoCommit(sendNotice); if (select != null) AddEntityNoCommit(select); }); return true; }); } ///// ///// 签到 已经被修改 ///// ///// ///// //[HttpPost, Route("UserDisAgree")] //public JsonActionResult UserDisAgree([FromBody] T_WB_REGISTER entity) //{ // return SafeExecute(() => // { // var register = GetEntity(t => t.ID == entity.ID); // var project = GetEntity(t => t.ID == register.PROJECT_ID); // var finishTask = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID); // var user = GetEntity(t => t.CODE == project.WB_USER_CODE); // register.STATUS = PFStandardStatus.Rejected; // var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("外包单位信息登记表-驳回", entity.ID, entity.ORG_ID, user.ID, user.NAME, DateTime.Now, DateTime.Now.AddDays(7), 1, "WB004"); // UnifiedCommit(() => // { // if (register != null) // UpdateEntityNoCommit(register); // if (sendNotice != null) // AddEntityNoCommit(sendNotice); // if (finishTask != null) // UpdateEntityNoCommit(finishTask); // }); // return true; // }); //} public static int CalculateAgeFromIDCard(string idCard) { // 验证身份证号码长度是否正确 if (idCard.Length != 18) { throw new ArgumentException("身份证号码必须是18位", nameof(idCard)); } // 提取出生年月日 string birthDateStr = idCard.Substring(6, 8); DateTime birthDate; if (!DateTime.TryParseExact(birthDateStr, "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out birthDate)) { throw new ArgumentException("身份证号码中的日期无效", nameof(idCard)); } // 获取当前日期 DateTime today = DateTime.Now; // 计算年龄 int age = today.Year - birthDate.Year; if (today.Month < birthDate.Month || (today.Month == birthDate.Month && today.Day < birthDate.Day)) { age--; } return age; } #region wyw /// /// 审核通过 /// /// /// [HttpPost, Route("UserAgreeNew")] public JsonActionResult UserAgreeNew([FromBody] T_PF_APPROVE entity) { return SafeExecute(() => { return ApproveCallBackService.CallBackNew("WB/WBRegister/UserAgreeNew", entity); }); } /// /// 获得单条实体数据 /// /// 过滤实体 /// [HttpPost, Route("GetRegister2")] public JsonActionResult GetRegister2([FromBody] KeywordFilter filter) { return SafeExecute(() => { var user2 = GetEntity(null, filter, null); if (user2 != null) { var reg = GetEntity(e => e.ID == user2.PARENT_ID); if (reg != null) { user2.PROJECT_ID = reg.PROJECT_ID; } //var user = GetEntity(e => e.CODE == user2.PHONE && e.PROJECT_ID.HasValue && !e.IS_DELETED); //if (user != null) //{ // user2.PROJECT_ID = user.PROJECT_ID; //} } return user2; }); } /// /// 外包单位信息录入 - 人员信息 (参考此页面 FullUpdate) /// /// 对象实体 /// [HttpPost, Route("FullUpdateUser")] public JsonActionResult Update([FromBody] T_WB_REGISTER_2 entity) { return SafeExecute(() => { if (entity.IS_LOGIN) { if (string.IsNullOrEmpty(entity.PHONE)) throw new Exception("需要登录的用户,手机号码必填!"); } if (entity.PARENT_ID == Guid.Empty) { if (entity.TaskID != Guid.Empty && APT.Infrastructure.Api.AppContext.CurrentSession.UserID.HasValue) { var taskAdd = GetEntity(e => e.USER_ID == APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value && e.SOURCE_FORMCODE == "WB004" && e.NOTICE_STATUS == 0); if (taskAdd != null && taskAdd.SOURCE_DATA_ID.HasValue) { entity.PARENT_ID = taskAdd.SOURCE_DATA_ID.Value; } } if (entity.PARENT_ID == Guid.Empty) throw new Exception("获取信息失败,请先关闭页面后重新添加此用户信息!"); } T_FM_USER_PRODUCTION_UNIT unit = null; List productionUnit = new List(); List belongRoles = new List(); T_FM_USER newUser = null; T_FM_USER UserEnable = null;//登录变成不可登录 T_FM_PERSON newPerson = null; if (!string.IsNullOrEmpty(entity.ID_CARD)) { entity.AGE = CalculateAgeFromIDCard(entity.ID_CARD); } bool isAddAll = true; if (entity.IS_LOGIN) { if (entity.WORKTYPE.HasValue) { var workTypeCheck = GetEntity(e => e.PARENT_ID == entity.PARENT_ID && e.IS_LOGIN && e.WORKTYPE.HasValue && e.WORKTYPE.Value == entity.WORKTYPE.Value && !e.IS_DELETED && e.ID != entity.ID); if (workTypeCheck != null) { throw new Exception("每个单位该工种只能添加一位可登录人员,审批根据工种找审批人!"); } } if (!entity.PROJECT_ID.HasValue) { throw new Exception("获取传参失败,请关闭页面后重试!"); } //var isrepeat = GetEntity(t => t.CODE == entity.PHONE && t.PROJECT_ID.HasValue && t.PROJECT_ID.Value == entity.PROJECT_ID.Value && !t.IS_DELETED); Expression> expression = t => t.CODE == entity.PHONE && t.PROJECT_ID.HasValue && t.PROJECT_ID.Value == entity.PROJECT_ID.Value && !t.IS_DELETED; if (entity.USERID.HasValue) { expression = t => t.ID == entity.USERID.Value; } var iListsrepeat = GetEntities(expression, null, null); if (iListsrepeat != null && iListsrepeat.Count() > 0) { //有对应手机号码信息 要么重复 要么修改 //if (isrepeat != null && isrepeat.ID != entity.ID && isrepeat.ENABLE_STATUS == 0 && !isrepeat.IS_DELETED) // throw new Exception("该手机号码已注册!"); var list = iListsrepeat.ToList(); if (list.Count() > 1 || list[0].NAME != entity.NAME) { throw new Exception("该手机号码已注册!"); } else { isAddAll = false; //信息修改 newUser = list[0]; newPerson = GetEntity(newUser.PERSON_ID.Value); newPerson.NAME = entity.NAME; newPerson.TEL = entity.PHONE; if (entity.SEX.HasValue) { newPerson.SEX = (int)entity.SEX.Value;//FMSexEnum FMSexEnum } else { newPerson.SEX = 1; } newUser.NAME = entity.NAME; newUser.SEX = newPerson.SEX; newUser.PHONE = entity.PHONE; newUser.ENTRYTIME = DateTime.Now; newUser.PROJECT_ID = entity.PROJECT_ID; newUser.ID_CARD = entity.ID_CARD; newUser.ENABLE_STATUS = (int)entity.ENABLE_STATUS;//登录 //if (entity.ENABLE_STATUS == FMEnableStatusEnum.禁用) //{ // newUser.ENABLE_STATUS = (int)entity.ENABLE_STATUS; //} } } else { //没有对应手机号码信息 if (entity.IS_LOGIN) { newUser = new T_FM_USER(); newPerson = new T_FM_PERSON(); newPerson.ID = Guid.NewGuid(); newPerson.ORG_ID = entity.ORG_ID; newPerson.CODE = entity.PHONE; newPerson.NAME = entity.NAME; newUser.ID = Guid.NewGuid(); newUser.ORG_ID = entity.ORG_ID; newUser.CODE = entity.PHONE; newUser.NAME = entity.NAME; if (entity.SEX.HasValue) { newPerson.SEX = (int)entity.SEX.Value;//FMSexEnum FMSexEnum } else { newPerson.SEX = 1; } newPerson.TEL = entity.PHONE; newUser.SEX = newPerson.SEX; newUser.PHONE = entity.PHONE; newUser.ENTRYTIME = DateTime.Now; newUser.PERSON_ID = newPerson.ID; newUser.PROJECT_ID = entity.PROJECT_ID; newUser.MineType = "_0_10_20_30_"; newUser.ID_CARD = entity.ID_CARD; var mineTypeList = newUser.MineType.Split("_", StringSplitOptions.RemoveEmptyEntries); unit = new T_FM_USER_PRODUCTION_UNIT(); foreach (var mineTypeItem in mineTypeList) { var enumList = this.GetEntity(t => t.CODE == "BSMineTypeEnum" && t.VALUE == int.Parse(mineTypeItem)); unit.ORG_ID = entity.ORG_ID; unit.USER_ID = newUser.ID; unit.ENUMS_ID = enumList?.ID; unit.Nav_Enums = null; productionUnit.Add(unit); } newUser.PASSWORD = "E10ADC3949BA59ABBE56E057F20F883E"; var role1 = this.GetEntity(t => t.NAME == "外包App用户"); var role2 = this.GetEntity(t => t.NAME == "外包作业员"); if (role1 != null) { T_FM_USER_BELONG_ROLE belongRole1 = new T_FM_USER_BELONG_ROLE(); belongRole1.USER_ID = newUser.ID; belongRole1.BELONG_ROLE_ID = role1.ID; belongRole1.ORG_ID = entity.ORG_ID; belongRoles.Add(belongRole1); } if (role2 != null) { T_FM_USER_BELONG_ROLE belongRole2 = new T_FM_USER_BELONG_ROLE(); belongRole2.USER_ID = newUser.ID; belongRole2.BELONG_ROLE_ID = role2.ID; belongRole2.ORG_ID = entity.ORG_ID; belongRoles.Add(belongRole2); } } } //人员部门信息赋值 if (newUser != null && !newUser.DEPARTMENT_ID.HasValue && entity.PROJECT_ID.HasValue) { var proj = GetEntity(entity.PROJECT_ID.Value, null); if (proj.DEPARTMENT_ID.HasValue) { newUser.DEPARTMENT_ID = proj.DEPARTMENT_ID.Value; } } } else { //如果不登录了 //T_WB_REGISTER_2//entity.USERID if (entity.USERID.HasValue) { var listCheckReg = GetEntities(e => e.ID != entity.ID && e.USERID.HasValue && e.USERID.Value == entity.USERID.Value && e.IS_LOGIN, null, null); if (listCheckReg == null || !listCheckReg.Any() || listCheckReg.Count() < 1) { UserEnable = GetEntity(e => e.ID == entity.USERID.Value && e.ENABLE_STATUS == 0); if (UserEnable != null) { UserEnable.ENABLE_STATUS = 1; } } } } var files1 = entity.Nav_Files1; var files2 = entity.Nav_Files2; var files3 = entity.Nav_Files3; var files4 = entity.Nav_Files4; var JobTypes = entity.Nav_JobTypes; entity.Nav_Files1 = null; entity.Nav_Files2 = null; entity.Nav_Files3 = null; entity.Nav_Files4 = null; entity.Nav_JobTypes = null; #region 后台配置了 但是接收时 可能 为空 重新赋值 if (files1 != null && files1.Any()) { foreach (var item in files1) { if (item.PARENT_ID == Guid.Empty) item.PARENT_ID = entity.ID; } } if (files2 != null && files2.Any()) { foreach (var item in files2) { if (item.PARENT_ID == Guid.Empty) item.PARENT_ID = entity.ID; } } if (files3 != null && files3.Any()) { foreach (var item in files3) { if (item.PARENT_ID == Guid.Empty) item.PARENT_ID = entity.ID; } } if (files4 != null && files4.Any()) { foreach (var item in files4) { if (item.PARENT_ID == Guid.Empty) item.PARENT_ID = entity.ID; } } if (JobTypes != null && JobTypes.Any()) { foreach (var item in JobTypes) { item.Nav_JobType = null; } } #endregion if (newUser != null && newUser.ID != Guid.Empty && entity.USERID == null) { entity.USERID = newUser.ID; } #region 人员信息变动 判断如果有人没有分数 外包单位现场安全员 如果没有 审批待办 给触发审批 #endregion UnifiedCommit(() => { if (newPerson != null) UpdateEntity(newPerson); if (newUser != null) UpdateEntity(newUser); if (UserEnable != null) UpdateEntity(UserEnable); if (belongRoles != null && belongRoles.Any()) BantchSaveEntityNoCommit(belongRoles); if (productionUnit != null && productionUnit.Any()) BantchSaveEntityNoCommit(productionUnit); UpdateEntity(entity); if (files1 != null && files1.Any()) BantchSaveEntityNoCommit(files1); if (files2 != null && files2.Any()) BantchSaveEntityNoCommit(files2); if (files3 != null && files3.Any()) BantchSaveEntityNoCommit(files3); if (files4 != null && files4.Any()) BantchSaveEntityNoCommit(files4); if (JobTypes != null && JobTypes.Any()) BantchSaveEntityNoCommit(JobTypes); }); //操作完成后入主库 if (entity.IS_LOGIN && isAddAll) { var Tenant = this.Request.Headers["Tenant"]; using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"])) { T_OP_ALLUSER alluser = new T_OP_ALLUSER(); alluser.CODE = entity.PHONE; alluser.TENANT = Tenant; alluser.ORG_ID = entity.ORG_ID; alluser.PHONE = entity.PHONE; context.AddEntity(alluser); context.SaveChanges(); } } return true; }); } /// /// 驳回 /// /// /// [HttpPost, Route("UserDisAgree")] public JsonActionResult RejectUpdate([FromBody] T_PF_APPROVE model) { return SafeExecute(() => { //公共 获取审批流信息 T_PF_APPROVE modelApp = null; List listAppDetail = null; T_FM_NOTIFICATION_TASK taskFinish = null; string Msg = string.Empty; bool ResultGetInfo = ApproveCallBackService.GetApproject(model, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg); if (!ResultGetInfo) throw new Exception("驳回失败!"); if (modelApp == null || listAppDetail == null) throw new Exception("获取驳回信息失败!"); //var entity = this.GetEntity(model.DATA_ID, new string[] { "Nav_ApplyUser" }); //entity.STATUS = PFStandardStatus.Rejected; // T_FM_NOTIFICATION_TASK notice = new T_FM_NOTIFICATION_TASK(); // if (entity.APPLY_USER_ID != null) // { // //发消息 // notice = NotificationTaskService.InsertUserNoticeTaskModel("安全检查通知表被驳回", entity.ID, entity.ORG_ID, (Guid)entity.APPLY_USER_ID, entity.Nav_ApplyUser?.NAME, DateTime.Now, //DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "SK006"); // } var register = GetEntity(t => t.ID == model.DATA_ID); var project = GetEntity(t => t.ID == register.PROJECT_ID); //var finishTask = NotificationTaskService.FOGetTaskFinishModel(model.TaskID, model.ID); var user = GetEntity(t => t.CODE == project.WB_USER_CODE); register.STATUS = PFStandardStatus.Rejected; var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("外包单位信息登记表-驳回", register.ID, register.ORG_ID, user.ID, user.NAME, DateTime.Now, DateTime.Now.AddDays(7), 1, "WB004"); UnifiedCommit(() => { if (register != null) UpdateEntityNoCommit(register); if (sendNotice != null) AddEntityNoCommit(sendNotice); if (modelApp != null) UpdateEntityNoCommit(modelApp); if (listAppDetail != null && listAppDetail.Count > 0) BantchUpdateEntityNoCommit(listAppDetail); if (taskFinish != null) UpdateEntityNoCommit(taskFinish); }); return true; }); } /// /// 新增外包人员 获取对应人员信息 /// /// /// [HttpPost, Route("GetRegisterAdd")] public JsonActionResult GetRegisterAdd([FromBody] KeywordFilter filter) { return SafeExecute(() => { var result = GetEntity(null, filter, null); if (result == null || result.ID == Guid.Empty) { string Phone = ""; if (filter.FilterGroup.Rules != null && filter.FilterGroup.Rules.Any()) { foreach (var item in filter.FilterGroup.Rules) { if (item.Field == "PHONE") { Phone = item.Value.ToString(); } } } if (!string.IsNullOrEmpty(Phone)) { var users = GetEntities(e => e.PHONE == Phone, null, null); if (users != null && users.Any() && users.Count() > 0) { T_FM_USER modelU = users.ToList()[0]; result = new T_WB_REGISTER_2() { ID = modelU.ID,//去前端判断是否现有人员 ORG_ID = modelU.ORG_ID, NAME = modelU.NAME, PHONE = modelU.PHONE, ID_CARD = modelU.ID_CARD, SEX = (FMSexEnum)modelU.SEX, USERID = modelU.ID, CREATE_TIME = DateTime.Now, CREATER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID, }; } } } return result; }); } /// /// 获得单条实体数据 /// /// 过滤实体 /// [HttpPost, Route("Get")] public JsonActionResult Get([FromBody] KeywordFilter filter) { return SafeExecute(() => { var result = GetEntity(null, filter, null); if (result.Nav_Item2 != null && result.Nav_Item2.Any()) { foreach (var item in result.Nav_Item2) { item.PROJECT_ID = result.PROJECT_ID; } } return result; }); } /// /// 更新或新增数据 /// /// 对象实体 /// [HttpPost, Route("FullUpdate1")] public JsonActionResult FullUpdate1([FromBody] T_WB_REGISTER_1 entity) { return SafeExecute(() => { var files = entity.Nav_Files; entity.Nav_Files = null; if (entity.END_TIME.HasValue && entity.END_TIME.Value.Date < DateTime.Now.Date) throw new Exception("协议结束时间不能小于当前日期!"); if (files != null && files.Any() && files.Count() > 0) foreach (var item in files) item.Nav_ImgFile = null; UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (files != null && files.Any()) BantchSaveEntityNoCommit(files); }); return true; }); } /// /// 更新或新增数据 /// /// 对象实体 /// [HttpPost, Route("FullUpdate3")] public JsonActionResult FullUpdate3([FromBody] T_WB_REGISTER_3 entity) { return SafeExecute(() => { var files = entity.Nav_Files; entity.Nav_Files = null; if (entity.VALID_TIME.HasValue && entity.VALID_TIME.Value.Date < DateTime.Now.Date) throw new Exception("证书有效期不能小于当前日期!"); entity.Nav_Level = null; if (files != null && files.Any() && files.Count() > 0) foreach (var item in files) item.Nav_ImgFile = null; UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (files != null && files.Any()) BantchSaveEntityNoCommit(files); }); return true; }); } /// /// 更新或新增数据 /// /// 对象实体 /// [HttpPost, Route("FullUpdate4")] public JsonActionResult FullUpdate4([FromBody] T_WB_REGISTER_4 entity) { return SafeExecute(() => { var files = entity.Nav_Files; entity.Nav_Files = null; if (entity.DATE_LIMIT.HasValue && entity.DATE_LIMIT.Value.Date < DateTime.Now.Date) throw new Exception("报告有效期不能小于当前日期!"); if (entity.IS_SPECIAL_DEVICE && (files == null || !files.Any() || files.Count() < 1)) throw new Exception("特种设备必须上传检测报告!"); if (files != null && files.Any() && files.Count() > 0) foreach (var item in files) item.Nav_ImgFile = null; UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (files != null && files.Any()) BantchSaveEntityNoCommit(files); }); return true; }); } #endregion } }