public async Task Update(PersonnelRtsInputDto input) { var data = await db.PersonnelRts.SingleOrDefaultAsync(m => m.Id == input.PersonnelRtsId && !m.IsDelete); if (data == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该需求不存在" })) }); } data.Age = input.Age; data.Education = input.Education; data.Number = input.Number; data.Position = input.Position; data.RecruitedNumber += input.RecruitedNumber; data.Sex = input.Sex; data.SkillRequirements = input.SkillRequirements; if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "更新失败" })) }); } }
public async Task Add(PersonnelRtsInputDto input) { var userId = ((UserIdentity)User.Identity).UserId; var related = await db.RelatedApprovals.SingleOrDefaultAsync(m => m.RelatedKey == "PersonnelRts"); if (related == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "人员需求申请未绑定审批流,添加失败" })) }); } var approval = await db.Approvals.Where(m => m.Key == related.ApprovalKey).ToListAsync(); if (approval == null && approval.Count <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = related.ApprovalKey + "该审批流不存在,添加失败" })) }); } var data = new PersonnelRts() { Id = IdentityManager.NewId(), AddbyId = userId, Age = input.Age, ApprovalType = EApprovalType.UnderReview, Education = input.Education, IsDelete = false, Number = input.Number, Position = input.Position, RecruitedNumber = input.RecruitedNumber, Sex = input.Sex, SkillRequirements = input.SkillRequirements, ApprovalIndex = 0, ApprovalKey = related.ApprovalKey }; db.PersonnelRts.Add(data); var userTypeKey = await db.Approvals.SingleOrDefaultAsync(m => m.Deis == 1 && m.Key == data.ApprovalKey); if (userTypeKey != null) { db.PersonnelRtsApprovals.Add(new PersonnelRtsApproval { Id = IdentityManager.NewId(), PersonnelRtsId = data.Id, IsApproval = false, UserTypeKey = userTypeKey.UserTypeKey, ApprovalIndex = 1 }); } else { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = data.ApprovalKey + "审批流异常" })) }); } if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }
public async Task UpdatePersonnelRtsApprovalType(PersonnelRtsInputDto input) { var userId = ((UserIdentity)User.Identity).UserId; var token = ((UserIdentity)User.Identity).Token; var userTypeKeys = token.UserTypeKey; var data = await db.PersonnelRts.SingleOrDefaultAsync(m => m.Id == input.PersonnelRtsId && !m.IsDelete); if (data == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该需求不存在" })) }); } data.ApprovalType = (EApprovalType)input.ApprovalType; if (data.ApprovalType == EApprovalType.Rejected) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该申请已被驳回" })) }); } var approval = await db.Approvals.Where(m => m.Key == data.ApprovalKey).ToListAsync(); if (approval == null && approval.Count <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = data.ApprovalKey + "该审批流不存在,请重新提交申请" })) }); } var index = data.ApprovalIndex + 1; var maxIndex = approval.Max(m => m.Deis); var userApproval = approval.SingleOrDefault(m => m.Deis == index); if (userApproval != null && input.ApprovalType == null) { if (!userTypeKeys.Contains(userApproval.UserTypeKey)) { //} //if (userApproval.UserTypeKey != token.UserTypeKey) //{ throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = data.ApprovalKey + "无权操作" })) }); } else { data.ApprovalIndex += 1; data.ApprovalType = EApprovalType.InExecution; //var personnelRtsApproval = await db.PersonnelRtsApprovals.SingleOrDefaultAsync(m => m.UserTypeKey == token.UserTypeKey && m.ApprovalIndex == index && m.PersonnelRtsId == data.Id); var personnelRtsApproval = await db.PersonnelRtsApprovals.SingleOrDefaultAsync(m => userTypeKeys.Contains(m.UserTypeKey) && m.ApprovalIndex == index && m.PersonnelRtsId == data.Id); if (personnelRtsApproval == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = data.ApprovalKey + "审批流程异常" })) }); } personnelRtsApproval.IsApproval = true; personnelRtsApproval.UserId = token.UserId; var userTypeKey = approval.SingleOrDefault(m => m.Deis == index + 1); if (userTypeKey != null) { db.PersonnelRtsApprovals.Add(new PersonnelRtsApproval { Id = IdentityManager.NewId(), PersonnelRtsId = data.Id, IsApproval = false, UserTypeKey = userTypeKey.UserTypeKey, ApprovalIndex = index + 1 }); } if (maxIndex == data.ApprovalIndex) { data.ApprovalType = EApprovalType.Reviewed; } } } else if (maxIndex == data.ApprovalIndex && input.ApprovalType == null) { data.ApprovalType = EApprovalType.Reviewed; } else { if (input.ApprovalType == EApprovalType.Rejected) { data.ApprovalType = (EApprovalType)input.ApprovalType; } } if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "更新失败" })) }); } }