/// <summary> /// (有参构造)反审核/收回 /// </summary> /// <param name="sysNo"></param> /// <param name="step"></param> /// <param name="userId"></param> public void AuditStepRollBack(int step, int userId) { BillSv bill = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(ap.sys_no); bill.BeforeRollBack(step); var ad = ap.ApplyDetails.Where(a => a.user_id == userId && a.pass != null).OrderByDescending(a => a.id).FirstOrDefault(); if (ad == null) { throw new Exception("还未审核或不是审核人,不能反审核"); } if (ap.ApplyDetails.Where(a => a.step > ad.step && a.pass != null).Count() > 0) { throw new Exception("后续步骤已被审核,不能反审核"); } ad.pass = null; ad.finish_date = null; ad.comment = null; ad.ip = null; if (ap.success != null) { ap.success = null; ap.finish_date = null; } db.SubmitChanges(); }
/// <summary> /// (有参)发送审批通知到下一个审批人 /// </summary> /// <param name="ap"></param> /// <param name="nextStep">下一步骤</param> /// <returns></returns> private bool SendEmailToNextAuditor(int nextStep) { string emailTemplate = @" <div>你好:</div> <div style='margin-left:30px;'> <div>你有一张待审核的流水号为{0}的单据,请尽快处理。</div> <table style='width:400px;font-size:14px;' border='0' cellpadding='0' cellspacing='3'> <tr><td style='width:100px'>公司:</td><td style='width:300px'>{1}</td></tr> <tr><td>申请人:</td><td>{2}</td></tr> <tr><td>办事处:</td><td>{3}</td></tr> <tr><td>单据类型:</td><td>{4}</td></tr> <tr><td>规格型号:</td><td>{5}</td></tr> <tr><td>审核步骤:</td><td>{6}</td></tr> </table> <br /> <div>单击以下链接可进入系统审核这张单据。</div> <div><a href='{7}{8}{9}{10}{11}'>内网用户点击此链接</a></div> <div><a href='{12}{8}{9}{10}{11}'>外网用户点击此链接</a></div> </div> "; var ads = ap.ApplyDetails.Where(a => a.pass != null); var auditorsEmailArr = ap.ApplyDetails.Where(a => a.step == nextStep).Select(a => a.User.email).ToArray(); string emailAddrs = string.Join(",", auditorsEmailArr); BillSv bs = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(ap.sys_no); string billType = bs.GetSpecificBillTypeName(); string stepName = ap.ApplyDetails.Where(a => a.step == nextStep).First().step_name; string depName = new UA((int)ap.user_id).GetUserDepartmentName(); string returnUrl = SomeUtils.MyUrlEncoder("Audit/BeginAudit?step=" + nextStep + "&applyId=" + ap.id); string emailContent = string.Format( emailTemplate, ap.sys_no, COP_NAME, ap.User.real_name, depName, billType, ap.p_model, stepName, WEB_ADDRESS, URL_PREFIX, returnUrl, ACCOUNT_PARAM, IS_INNER_FRAME, OUT_ADDRESS ); return(new EmailUtil().SendEmail(emailContent, emailAddrs, null, billType + "审批")); }
/// <summary> /// (有参)发送审批完成通知给申请者 /// </summary> /// <param name="ap"></param> /// <returns></returns> private bool SendEmailToApplier() { string emailTemplate = @" <div>你好:</div> <div style='margin-left:30px;'> <div>你申请的流水号为{0}的单据已经处理完毕,结果如下。</div> <table style='width:400px;font-size:14px;' border='0' cellpadding='0' cellspacing='3'> <tr><td style='width:100px'>公司:</td><td style='width:300px'>{1}</td></tr> <tr><td>单据类型:</td><td>{2}</td></tr> <tr><td>规格型号:</td><td>{3}</td></tr> <tr><td>申请结果:</td><td>{4}</td></tr>" + (ap.success == true ? "{5}" : @" <tr><td>失败原因:</td><td>{5}</td></tr> ") + @" </table> </div> "; BillSv bs = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(ap.sys_no); string billType = bs.GetSpecificBillTypeName(); string ccEmails = null; var ife = bs as IFinishEmail; if (ife != null) { ccEmails = ife.ccToOthers(ap.sys_no, ap.success ?? false); } string emailContent = string.Format( emailTemplate, ap.sys_no, COP_NAME, billType, ap.p_model, ap.success == true ? "申请成功" : "申请失败", ap.success == true ? "" : ap.ApplyDetails.Where(ad => ad.pass == false).First().comment ); return(new EmailUtil().SendEmail(emailContent, ap.User.email, ccEmails, billType + "申请完成")); }
/// <summary> /// (有参)发送挂起通知邮件 /// </summary> /// <param name="operatorName">操作人</param> /// <param name="reason">挂起原因</param> /// <returns></returns> private bool SendBlockNotification(string operatorName, string reason) { bool sendEmail = bool.Parse(ConfigurationManager.AppSettings["SendEmail"]); if (!sendEmail) { return(true); } string emailTemplate = @" <div>你好:</div> <div style='margin-left:30px;'> <div>你申请的流水号为{0}的单据被挂起,详细如下:</div> <table style='width:400px;font-size:14px;' border='0' cellpadding='0' cellspacing='3'> <tr><td style='width:100px'>公司:</td><td style='width:300px'>{1}</td></tr> <tr><td>单据类型:</td><td>{2}</td></tr> <tr><td>规格型号:</td><td>{3}</td></tr> <tr><td>挂起操作人:</td><td>{4}</td></tr> <tr><td>挂起原因:</td><td>{5}</td></tr> </table> </div> "; BillSv bs = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(ap.sys_no); string billType = bs.GetSpecificBillTypeName(); string emailContent = string.Format( emailTemplate, ap.sys_no, COP_NAME, billType, ap.p_model, operatorName, reason ); return(new EmailUtil().SendEmail(emailContent, ap.User.email, null, billType + "被挂起")); }
/// <summary> /// 总裁办批量处理申请单 /// </summary> /// <param name="applyDetailIds"></param> /// <param name="userId"></param> /// <param name="isPass"></param> /// <param name="comment"></param> /// <param name="ipAdd"></param> /// <returns></returns> public string CeoBatchAudit(int[] applyDetailIds, int userId, bool isPass, string comment, string ipAdd) { int record = 0; foreach (int detailId in applyDetailIds) { var ad = db.ApplyDetails.SingleOrDefault(a => a.id == detailId); ap = ad.Apply; if (ap.success != null) { continue; } var details = ap.ApplyDetails.ToList(); if (ad.pass != null) { continue; } else { if (ad.countersign == null || ad.countersign == false) { if (details.Where(a => a.step == ad.step && a.pass == true).Count() > 0) { continue; } } } BillSv bill = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(ap.sys_no); //审批之前,单据需要做的事,批量处理的时候不做,不然时间太长 //try { // bill.DoWhenBeforeAudit((int)ad.step, ad.step_name, isPass, userId); //} //catch { // continue; //} ad.pass = isPass; ad.comment = comment; ad.ip = ipAdd; ad.finish_date = DateTime.Now; //是否最后一步审批 bool isLastStep = ad.step == details.Max(a => a.step); if (isLastStep && ad.countersign == true) { if (details.Where(a => a.step == ad.step && a.pass == null && a.user_id != userId).Count() > 0) { isLastStep = false; } } if (!isPass || isLastStep) { ap.success = isPass; ap.finish_date = DateTime.Now; //审批完成之后需要做的事情 bill.DoWhenFinishAudit(isPass); } try { db.SubmitChanges(); } catch { continue; } SendNotificationEmail(); record++; } return("已批量处理" + record.ToString() + "行记录"); }
/// <summary> /// (无参构造)提交申请 /// </summary> /// <param name="orderType">单据类型</param> /// <param name="userId">申请人ID</param> /// <param name="userName">申请人姓名</param> /// <param name="ipAddr">ip地址</param> /// <param name="sysNo">流水号</param> /// <param name="pModel">规格型号</param> /// <param name="pro">流程对象</param> /// <param name="auditorsDic">审核关系字典</param> /// <returns></returns> public void BeginApply(string orderType, int userId, string userName, string ipAddr, string sysNo, string pModel, string pCustomer, Process pro, Dictionary <string, int?> auditorsDic) { if (db.Apply.Where(a => a.sys_no == sysNo).Count() > 0) { throw new Exception("单据已提交,不能重复操作"); } try { BillSv bill = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(sysNo); bill.DoWhenBeforeApply(); } catch (Exception ex) { throw new Exception(ex.Message); } ap = new Apply(); ap.user_id = userId; ap.user_name = userName; ap.sys_no = sysNo; ap.p_model = pModel; ap.p_customer = pCustomer; ap.order_type = orderType; ap.start_date = DateTime.Now; ap.ip = ipAddr; int minusStep = 0; List <ApplyDetails> ads = new List <ApplyDetails>(); foreach (var det in pro.ProcessDetail.OrderBy(p => p.step)) { var auditorRel = db.AuditorsRelation.Where(a => a.step_value == det.stepType); string relateType = auditorRel.First().relate_type; string stepName = auditorRel.First().step_name; List <int?> auditors = new List <int?>(); int? dicValue = 0; switch (relateType) { case "固定人员": auditors.Add(det.userId); break; case "申请者": auditors.Add(userId); break; default: //其它除了从表单直接传过来的审核人,全部通过关联关系进行查询审核人。统一使用关联类型+“NO"这个变量名,值从上一级传进来 string realteTypeID = relateType + "NO"; if (auditorsDic != null && auditorsDic.TryGetValue(realteTypeID, out dicValue)) { if (relateType.StartsWith("表单")) { //如果以表单开头,表示是从表单直接选择审核人员,那么不用关联直接加入审核人 auditors.Add(dicValue); } else { auditors = auditorRel.Where(a => a.relate_value == dicValue).Select(a => a.auditor_id).ToList(); } } break; } if (auditors.Count() < 1) { if (det.canBeNull == false) { throw new Exception("步骤【" + det.stepName + "】审核人员不存在"); } else if (det.isCountersign == null || det.isCountersign == false) { //该步骤的审核人为空且被允许,所以不是会签的要将后续步骤-1 minusStep++; } continue; } foreach (int auditor in auditors) { ads.Add(new ApplyDetails() { Apply = ap, can_modify = det.canModify, step = det.step - minusStep, step_name = det.isCountersign == true ? det.stepName + "(" + stepName.Substring(stepName.IndexOf("_") + 1).Split(new string[] { "审", "负" }, StringSplitOptions.None)[0] + ")" : det.stepName, user_id = auditor, countersign = det.isCountersign }); } } try { db.Apply.InsertOnSubmit(ap); db.ApplyDetails.InsertAllOnSubmit(ads); db.SubmitChanges(); } catch (Exception ex) { throw ex; } SendNotificationEmail(); }
/// <summary> /// (有参构造)开始审核 /// </summary> /// <param name="step">步骤</param> /// <param name="userId">用户ID</param> /// <param name="isPass">是否通过</param> /// <param name="comment">意见</param> /// <returns></returns> public string HandleAudit(int step, int userId, bool isPass, string comment, string ipAdd) { if (ap.success != null) { return("此申请已结束"); } var details = ap.ApplyDetails.ToList(); var ad = details.Where(a => a.step == step && a.user_id == userId).OrderBy(a => a.pass).First(); if (ad.pass != null) { return("不能重复审批"); } else { if (ad.countersign == null || ad.countersign == false) { if (details.Where(a => a.step == step && a.pass == true).Count() > 0) { return("已被同组其它人审批"); } } } BillSv bill = (BillSv) new BillUtils().GetBillSvInstanceBySysNo(ap.sys_no); //审批之前,单据需要做的事 try { bill.DoWhenBeforeAudit(step, ad.step_name, isPass, userId); } catch (Exception ex) { return(ex.Message); } ad.pass = isPass; ad.comment = comment; ad.ip = ipAdd; ad.finish_date = DateTime.Now; //是否最后一步审批 bool isLastStep = ad.step == details.Max(a => a.step); if (isLastStep && ad.countersign == true) { if (details.Where(a => a.step == ad.step && a.pass == null && a.user_id != userId).Count() > 0) { isLastStep = false; } } if (!isPass || isLastStep) { ap.success = isPass; ap.finish_date = DateTime.Now; } try { db.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } if (!isPass || isLastStep) { //审批完成之后需要做的事情 try { bill.DoWhenFinishAudit(isPass); } catch (Exception ex) { return("审批成功;但发生以下错误:" + ex.Message + ";可尝试收回后重试,如果还是出现,请联系管理员处理"); } } SendNotificationEmail(); return(""); }