/// <summary> /// 获取分销商申请的审批历史记录 /// </summary> /// <param name="applyId"></param> public List <DistributionApplyAuditListDTO> GetApplyAuditListExt(Guid applyId) { var audits = DistributionApplyAudit.ObjectSet() .Where(x => x.ApplyId == applyId) .OrderByDescending(x => x.SubTime) .ToList(); if (audits.Count > 0) { var users = CBCSV.Instance.GetUserNameAccountsByIds(audits.Select(x => x.SubId).ToList()); Func <Guid, string> getUserName = (subId) => { if (users == null) { return(subId.ToString()); } var user = users.FirstOrDefault(x => x.userId == subId); return(user == null?subId.ToString() : user.userName); }; var auditDtos = audits.Select(x => new DistributionApplyAuditListDTO(x.ToEntityData(), getUserName(x.SubId))) .ToList(); return(auditDtos); } return(new List <DistributionApplyAuditListDTO>()); }
/// <summary> /// 更新DistributionApply表,插入DistributionApplyAudit记录 /// </summary> /// <param name="applyId"></param> /// <param name="isAuditing"></param> /// <param name="isAuditingPass"></param> /// <param name="txt"></param> /// <returns></returns> private ResultDTO <DistributionApply> UpdateDistributionApplyAndAudit(Guid applyId, bool isAuditing, bool isAuditingPass, string txt) { ContextSession contextSession = ContextFactory.CurrentThreadContext; var now = DateTime.Now; var apply = DistributionApply.ObjectSet().FirstOrDefault(t => t.Id == applyId); if (apply == null) { return new ResultDTO <DistributionApply> { isSuccess = false, ResultCode = 0, Message = "没有找到ID='" + applyId + "'的数据!", Data = null } } ; var refuseTxt = ""; var detailTxt = ""; if (isAuditing) { if (isAuditingPass) { if (apply.State.EnumValue == DistributeApplyStateEnum.Audit) { return new ResultDTO <DistributionApply> { isSuccess = false, ResultCode = 0, Message = "此申请已经通过审核,不能重复通过审核!", Data = null } } ; apply.State = new DistributionApplySate { EnumValue = DistributeApplyStateEnum.Audit, Value = (int)DistributeApplyStateEnum.Audit }; } else { apply.State = new DistributionApplySate { EnumValue = DistributeApplyStateEnum.AuditRefuse, Value = (int)DistributeApplyStateEnum.AuditRefuse }; apply.RefuseReason = txt; refuseTxt = txt; } } else { apply.Remarks = txt; detailTxt = txt; } apply.ModifiedOn = now; apply.EntityState = EntityState.Modified; //IsPass取当前entity的状态 var isPass = apply.State.EnumValue == DistributeApplyStateEnum.Audit; var audit = new DistributionApplyAudit { Id = Guid.NewGuid(), ApplyId = applyId, SubTime = now, SubId = ContextDTO.LoginUserID, Details = detailTxt, RefuseReason = refuseTxt, IsPass = isPass, EntityState = EntityState.Added }; contextSession.SaveObject(audit); contextSession.SaveChanges(); return(new ResultDTO <DistributionApply> { isSuccess = true, ResultCode = 1, Data = apply }); }