// ------------------------------------------------------- // 保存 删除 // ------------------------------------------------------- #region 函数:Save(BugInfo param) /// <summary>保存记录</summary> /// <param name="param">BugInfo 实例详细信息</param> /// <param name="message">数据库操作返回的相关信息</param> /// <returns>BugInfo 实例详细信息</returns> public BugInfo Save(BugInfo param) { if (string.IsNullOrEmpty(param.Id)) { throw new Exception("实例标识不能为空。"); } bool isNewObject = !this.IsExist(param.Id); BugInfo originalObject = isNewObject ? null : this.FindOne(param.Id); string methodName = isNewObject ? "新增" : "编辑"; if (isNewObject) { IAccountInfo account = KernelContext.Current.User; param.AccountId = account.Id; param.AccountName = account.Name; } // 指派问题负责人 if (string.IsNullOrEmpty(param.AssignToAccountId)) { param.AssignToAccountName = string.Empty; } else { param.AssignToAccountName = MembershipManagement.Instance.AccountService[param.AssignToAccountId].Name; } // 生成问题编号 if (string.IsNullOrEmpty(param.Code)) { string code = string.Empty; // 所属类别信息 ApplicationInfo application = AppsContext.Instance.ApplicationService[BugConfiguration.ApplicationName]; // 编号的相关实体数据表 string entityTableName = BugConfigurationView.Instance.DigitalNumberEntityTableName; // 编号的前缀编码 string prefixCode = BugConfigurationView.Instance.DigitalNumberPrefixCodeRule .Replace("{ApplicationPinYin}", application.PinYin); // 编号的自增流水号长度 int incrementCodeLength = BugConfigurationView.Instance.DigitalNumberIncrementCodeLength; GenericSqlCommand command = this.provider.CreateGenericSqlCommand(); code = DigitalNumberContext.GenerateDateCodeByPrefixCode(command, entityTableName, prefixCode, incrementCodeLength); param.Code = code.ToUpper(); } // 过滤 Cross Site Script param = StringHelper.ToSafeXSS <BugInfo>(param); this.provider.Save(param); param = this.FindOne(param.Id); if (isNewObject) { originalObject = param; } // 记录问题状态信息 BugHistoryInfo history = new BugHistoryInfo(); history.Id = StringHelper.ToGuid(); history.BugId = param.Id; if (isNewObject) { // 0.新问题 | 1.确认中 | 2.处理中 | 3.已解决 | 4.已关闭 history.FromStatus = 0; history.ToStatus = 0; BugContext.Instance.BugHistoryService.Save(history); } else { history.FromStatus = (param.Properties["FromStatus"] == null) ? 0 : Convert.ToInt32(param.Properties["FromStatus"].ToString()); history.ToStatus = param.Status; if (history.FromStatus != history.ToStatus) { BugContext.Instance.BugHistoryService.Save(history); } } // 发送邮件提醒 // 新问题状态发送给负责人, 已解决状态发送给提交人 if (BugConfigurationView.Instance.SendMailAlert == "ON" // && isNewObject || (param.ModifiedDate.AddHours(2) > originalObject.ModifiedDate) && (param.Status == 0 || param.Status == 3)) { if (isNewObject || (param.Status != originalObject.Status || param.AssignToAccountId != originalObject.AssignToAccountId)) { string mailTo, mailSubject, mailBody; IMemberInfo member = null; if (param.Status == 3) { // 已解决的问题, 发邮件通知提交人 member = MembershipManagement.Instance.MemberService.FindOneByAccountId(param.AccountId); } else { member = MembershipManagement.Instance.MemberService.FindOneByAccountId(param.AssignToAccountId); } if (member != null && !string.IsNullOrEmpty(member.Email)) { VelocityContext context = new VelocityContext(); // 加载当前实体数据信息 context.Put("kernelConfiguration", KernelConfigurationView.Instance); // 加载当前实体数据信息 context.Put("param", param); mailTo = member.Email; mailSubject = mailBody = string.Empty; if (param.Status == 0) { // 0.新的问题 mailSubject = "您有一个新问题【" + param.Title + "】,等待处理。"; mailBody = VelocityManager.Instance.ParseTemplateVirtualPath(context, "/resources/email/Bug/bugzilla-new-mail.vm"); } else if (param.Status == 3) { // 3.已解决 mailSubject = param.AssignToAccountId + "已将问题【" + param.Title + "】解决,请确认。"; mailBody = VelocityManager.Instance.ParseTemplateVirtualPath(context, "/resources/email/Bug/bugzilla-resolved-mail.vm"); } EmailClientContext.Instance.Send(mailTo, mailSubject, mailBody, EmailFormat.Html); } } } return(param); }