using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web; using PMS.BusinessModels.Account; using PMS.BusinessModels.Problem; using PMS.BusinessService.SysManager; using PMS.BusinessService.WorkFlow; using PMS.DBService.Problems; using PMS.Interface.Problems; using QWPlatform.SystemLibrary; using QWPlatform.SystemLibrary.LogManager; using PMS.EntityModels.Product; using QWPlatform.SystemLibrary.Utils; using PMS.BusinessModels.MobileProblem; using System.Web.UI; using PMS.EntityModels.NoticeManager; using PMS.Plugins.Common; namespace PMS.BusinessService.Problems { /// /// 问题查询业务层 /// public class ProjectQueryBusiness : IProjectProblems { //创建一个工作流服务接口 WorkFlowBLLService workflowBll = QWPlatform.SystemLibrary.Provider.SingletonProvider.Instance; //系统配置 SysConfigBLLServier configBll = QWPlatform.SystemLibrary.Provider.SingletonProvider.Instance; //账户信息 AccountBLLService account = QWPlatform.SystemLibrary.Provider.SingletonProvider.Instance; //数据服务层 QueryDBService queryDbService = QueryDBService.Instance(); /// /// 查询问题列表结果 /// /// /// public string GetProjectListDataGridJson(QueryModel queryModel) { var total = 0; var dt = queryDbService.Query(queryModel, out total); return QWPlatform.SystemLibrary.Utils.Strings.ObjectToJson( new { total = total, rows = dt }); } /// /// V2版本导出 /// /// /// public string GetProjectListDataGridJsonV2(QueryModel queryModel) { var total = 0; var dt = new List(); var dataTable = queryDbService.Query(queryModel, out total); if (dataTable.Rows.Count > 0) { dt = Tools.ConvertToList(dataTable); } return QWPlatform.SystemLibrary.Utils.Strings.ObjectToJson( new { total = total, rows = dt }); } public DataTable CreateExcel(QueryModel queryModel) { var total = 0; return queryDbService.Query(queryModel, out total); } /// /// 获取待处理的问题列表json(左侧显示)显示不用控制权限? /// /// 1:技术支持,2:研发显示 /// /// /// /// 返回datagrid的json public string GetNeedProccessProjectListJson(int type, string productid, string productModuleId, int page, int rows) { var total = 0; var dt = queryDbService.QueryNeedProccessList(type, productid, productModuleId, page, rows, out total); return QWPlatform.SystemLibrary.Utils.Strings.ObjectToJson( new { total = total, rows = dt }); } /// /// 受理问题 /// /// 问题ID /// 受理人id /// 受理人名称 /// 返回受理结果的json public bool ReceiveProblem(string id, string userid, string name) { //查询这个问题是否被受理 return queryDbService.ReceiveProblem(id, userid, name); } /// /// 判断问题是否被他人受理(0:未受理,1:他人受理,2:我受理) /// /// /// /// public int IsReceive(string id, string userid) { return queryDbService.IsReceive(id, userid); } /// /// 尝试使用新人员来进行受理该问题 /// /// /// /// /// public bool TryReceiveProblem(string id, string userid, string name) { //强制受理这个问题 return queryDbService.TryReceiveProblem(id, userid, name); } /// /// 获取最近处理描述 /// /// /// public ProblemDealMessage GetRecentlyDetail(string ProblemId) { return queryDbService.GetRecentlyDetail(ProblemId); } /// /// 取消问题受理 /// /// 问题ID /// 返回是否取消成功 public bool CancelReceiveProblem(string id, string PersonId) { return queryDbService.CancelReceiveProblem(id, PersonId); } /// /// 处理问题(包括:指派人员,解决问题,回退,终止问题等) /// /// /// public bool ExecuteProcessData(ProblemProcessModel model, out string message,UserInfo user) { message = string.Empty; try { //处理的过程ID var processid = string.Empty; var re = false; if (model.IsAssign) {//指派人员处理 re = this.AssignUser(model, out processid); } else if (model.IsDeal) {//处理问题(未解决) re = this.Deal(model, out processid); } else if (model.IsSolve) {//直接解决问题 re = this.Solve(model, out processid,user); } else if (model.IsStop) {//终止问题 re = this.Stop(model, out processid); } else if (model.IsBack) {//回退问题 re = this.Back(model, out processid); if (!re) {//回退失败 message = "回退失败,如果是当前环节点提交的问题无法回退"; } } else if (model.IsCommit) {//向上提交问题 re = this.Commit(model); } else if (model.IsBackStart) {//回退问题 re = this.BackStart(model, out processid); if (!re) {//回退失败 message = "回退失败,如果是当前环节点提交的问题无法回退"; } } if (re) {//更新附加信息 UpdateProblemInfo(model,user); //处理的过程ID model.ProcesssID = processid; //通知线程(邮件等) ThreadPool.QueueUserWorkItem(new WaitCallback(Notify), model); } else {//问题处理失败 message = "问题处理失败,请确认当前人员职务是否正确"; } return re; } catch (Exception ex) { message = "处理问题失败:" + ex.Message; Logger.Instance.Error("处理问题失败,ID:" + model.ProblemID, ex); return false; } } #region 问题的处理模式 //指派用户处理 private bool AssignUser(ProblemProcessModel model, out string proccessid) { proccessid = string.Empty; var uid = model.AssignID; var name = model.AssignName; //查询出被指派人员的性质与职务 DataTable dt = queryDbService.QueryUserInfo(uid); var user_property = dt.GetValueByName("性质"); var user_jobcode = dt.GetValueByName("职务"); //获取到workid var workid = workflowBll.GetDealWorkId(model.ProblemID, user_property, user_jobcode); var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, NextWorkId = workid, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, AssignPersonId = model.AssignID, AssignPersonName = model.AssignName, }; return workflowBll.ProblemAssgin(pdealModel, out proccessid); } //处理问题(未解决) private bool Deal(ProblemProcessModel model, out string proccessid) { //获取到workid var workid = workflowBll.GetDealWorkId(model.ProblemID, model.CurrentUserProp, model.CurrentUserJob); var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, DealPeronName = model.CurrentUserName, NextWorkId = workid }; //处理过程ID,用于附件上传 proccessid = string.Empty; return workflowBll.ProblemDeal(pdealModel, out proccessid); } //直接解决问题 private bool Solve(ProblemProcessModel model, out string proccessid,UserInfo user) { //获取到workid var workid = workflowBll.GetDealWorkId(model.ProblemID, model.CurrentUserProp, model.CurrentUserJob); var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, DealPeronName = model.CurrentUserName, NextWorkId = workid, Solution = model.SolveRemark, Version = "", ProblemTypeID = model.ProblemTypeID, TestPeronId=model.TestPeronId, VersionID=model.VersionID, }; //处理过程ID,用于附件上传 proccessid = string.Empty; return workflowBll.ProblemSolution(pdealModel, out proccessid,user); } //终止问题 private bool Stop(ProblemProcessModel model, out string proccessid) { var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, ProblemTypeID = model.ProblemTypeID }; //处理过程ID,用于附件上传 proccessid = string.Empty; return workflowBll.ProblemBreak(pdealModel, out proccessid); } //回退问题(回退到上一个流程) private bool Back(ProblemProcessModel model, out string proccessid) { //处理过程ID,用于附件上传 proccessid = string.Empty; //获取回退流程ID var workid = workflowBll.GetBackProblemWorkFlowID(model.ProblemID); if (workid == 0) {//无法回退 return false; } else {//可以回退 var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, NextWorkId = workid, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, ProblemTypeID=model.ProblemTypeID }; return workflowBll.ProblemRollBack(pdealModel, out proccessid); } } //回退问题(回退到项目流程) private bool BackStart(ProblemProcessModel model, out string proccessid) { //处理过程ID,用于附件上传 proccessid = string.Empty; //获取回退流程ID var workid = 2; var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, NextWorkId = workid, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, ProblemTypeID = model.ProblemTypeID }; return workflowBll.ProblemRollBack(pdealModel, out proccessid); } //提交问题 private bool Commit(ProblemProcessModel model) { //获取下一流程的ID var workid = workflowBll.GetSubmitProblemWorkFlowID(model.CurrentUserProp, model.ProblemID); var pdealModel = new ProblemDealModel() { ProblemId = model.ProblemID, NextWorkId = workid, Describe = model.ProcessRemark, DealPeronId = model.CurrentUserID, SubID = model.SubID, SubName = model.SubName, ProblemTypeID = model.ProblemTypeID }; return workflowBll.ProblemSubmit(pdealModel); } //更新问题的其它信息(研发或支持使用) private void UpdateProblemInfo(ProblemProcessModel model,UserInfo user) { if (model.IsAttInfo) {//执行更新(问题类型:产品问题/项目问题),解决版本,BH版本号,BH编号,常见问题,修改说明,升级说明,是否发布,需要培训 queryDbService.UpdateProblemInfo(model,user); } } #endregion #region 首页问题数量 public DataTable QueryNotFinishProblem(string uid, int userprop, string companyid, string projectid, string orgid) { return queryDbService.QueryNotFinishProblem(uid, userprop, companyid, projectid, orgid); } public string NotFinishProblemList(string uid, int userprop, string companyid, string projectid, string orgid, int Type, int page, int rows) { var total = 0; var dt = queryDbService.NotFinishProblemList(uid, userprop, companyid, projectid, orgid, Type, page, rows, out total); return Strings.ObjectToJson(new { total = total, rows = dt }); } //返回各渠道的问题信息 public DataTable QueryCompanyProblemCount() { return queryDbService.QueryCompanyProblemCount(); } //返回各机构的问题数量 public DataTable QueryOrgProblemCount(string companyid) { return queryDbService.QueryOrgProblemCount(companyid); } //返回该机构下的人员数量 public DataTable QueryOrgPersonProblemCount(string orgid) { return queryDbService.QueryOrgPersonProblemCount(orgid); } //返回我的问题列表 public DataTable QueryMyProblemList(string userid) { return queryDbService.QueryMyProblemList(userid); } //常见问题top5 public DataTable QueryOftenProblemList() { return queryDbService.QueryOftenProblemList(); } //返回问题停留位置 public DataTable QueryAllProblemStopWorkFlow(int personProp, string companyid, string orgid, string userid) { return queryDbService.QueryAllProblemStopWorkFlow(personProp, companyid, orgid, userid); } #endregion /// /// 查询出过程的详细信息 /// /// /// public dynamic QueryProcessInfo(string pid) { return queryDbService.QueryProcessInfo(pid); } /// /// 获取问题记录 /// /// /// public EntityModels.Product.WTJLModel GetWTJLModel(string id) { return queryDbService.GetModel(id); } /// /// 获取问题记录datatable /// /// /// public string GetProblemById(string id) { return queryDbService.GetProblemById(id).ToJson(); } /// /// 获取问题ID /// /// /// public string GetWTID(string Processid) { return queryDbService.GetWTID(Processid); } /// /// 登记问题时获取推送人 /// /// /// public List GetPushPerson(string ProblemId) { return queryDbService.GetPushPerson(ProblemId); } /// /// 获取问题主流程 /// /// /// public string GetMainProcess(string ProblemId) { return Strings.ObjectToJson(queryDbService.GetMainProcess(ProblemId)); } /// /// 查询个人配置 /// /// /// public NotefiyConfigInfo GetNotifyConfigInfoByUserId(string PersonId) { return account.GetNotifyConfigInfoByUserId(PersonId); } //使用另外一线程发起通知 public void Notify(object model) { //接收邮件的对象 List emailList = new List(); var emailConfig = configBll.GetEmailConfig(); if (emailConfig.IsActive) {//服务器启用的邮件通知 //获取问题信息 var processModel = model as ProblemProcessModel; var problemModle = queryDbService.GetModel(processModel.ProblemID); var title = ""; //邮件标题 var body = string.Format("问题编号:{0}\r\n问题标题:{1}\r\n处理人:{2}\r\n处理日期:{3}\r\n", problemModle.BH, problemModle.WTBT, processModel.CurrentUserName, DateTime.Now); if (processModel.IsAssign) {//问题被指派人的邮件(根据指派人ID,查询出邮件及是否允许发送) var config = account.GetNotifyConfigInfoByUserId(processModel.AssignID); if (config != null) { if (config.Assign.SendEmail && !string.IsNullOrEmpty(config.Email)) {//需要添加一个邮件收信人 emailList.Add(config.Email); title = string.Format("PMS[{0}]问题指派给您处理", problemModle.BH); } } } else if (processModel.IsSolve) {//解决问题(通知问题登记人) var config = account.GetNotifyConfigInfoByUserId(problemModle.DJRID); if (config != null) { if (config.SolveTime.SendEmail && !string.IsNullOrEmpty(config.Email)) {//需要添加一个邮件收信人 emailList.Add(config.Email); title = string.Format("PMS[{0}]问题已解决", problemModle.BH); } } } else if (processModel.IsStop) {//问题被终止 var config = account.GetNotifyConfigInfoByUserId(problemModle.DJRID); if (config != null) { if (config.StopTime.SendEmail && !string.IsNullOrEmpty(config.Email)) {//需要添加一个邮件收信人 emailList.Add(config.Email); title = string.Format("PMS[{0}]问题被终止", problemModle.BH); } } } else if (processModel.IsBack) {//问题被回退 var config = account.GetNotifyConfigInfoByUserId(problemModle.DJRID); if (config != null) { if (config.BackTime.SendEmail && !string.IsNullOrEmpty(config.Email)) {//需要添加一个邮件收信人 emailList.Add(config.Email); title = string.Format("PMS[{0}]问题被回退", problemModle.BH); } } } var emailServerInfo = new QWPlatform.SystemLibrary.Email.EmailServerInfo(emailConfig.EmailServer, emailConfig.SendName, emailConfig.SendEmail, emailConfig.SendPassword, emailConfig.Port); //执行邮件发送 QWPlatform.SystemLibrary.Email.SmtpEmail smtpEmail = new QWPlatform.SystemLibrary.Email.SmtpEmail(emailServerInfo); var emailInfo = new QWPlatform.SystemLibrary.Email.EmailInfo(title, body, emailList.ToArray(), new string[] { }); emailInfo.FromUser(emailConfig.SendEmail, emailConfig.SendName); if (emailList.Count > 0) { var r = smtpEmail.Send(emailInfo); if (!r) {//送信失败 Logger.Instance.Warn("邮件发送失败,请检查密码或服务器配置是否正确"); } } } } //撤销问题处理 public int UndoProblem(string id) { return queryDbService.UndoProblem(id); } public string CheckUpdateProcess(string ProcessId, string UserId) { return queryDbService.CheckUpdateProcess(ProcessId, UserId); } public bool UpdateProblemProcess(WTJLGCModel model) { return queryDbService.UpdateProblemProcess(model) > 0; } /// /// 判断是否处理过该问题 /// /// /// public bool IsDealed(string id, string PersonId) { return queryDbService.IsDealed(id, PersonId); } /// /// 判断问题是否完结并处理推送评价 /// /// 问题id /// /// public bool IsConfirmClosing(string id, string PersonId) { return queryDbService.IsConfirmClosing(id, PersonId); } /// /// 问题归类 /// /// /// public bool DoClassifi(string id, string ClssID, int nature, UserInfo user) { return queryDbService.DoClassifi(id, ClssID, nature, user); } /// /// 重复问题列表所用的数据 /// /// /// public string AllProList(UserInfo userInfo) { return queryDbService.AllProList(userInfo).ToJson(); } #region 超时推送 public bool GetIsOverTime(UserInfo user) { return queryDbService.GetIsOverTime(user); } public string GetAcceptOverTime(UserInfo user) { return queryDbService.GetAcceptOverTime(user).ToJson(); } public string GetDealOverTime(UserInfo user) { return queryDbService.GetDealOverTime(user).ToJson(); } #endregion #region 版本问题 public string GetVersionProblem(string SearchText, string ProductId, string VersionId, string projectId, string AcceptedId, string sort, string order, int page, int rows) { var total = 0; var dt = queryDbService.GetVersionProblem(SearchText, ProductId, VersionId, projectId, AcceptedId, sort, order, page, rows, out total); return QWPlatform.SystemLibrary.Utils.Strings.ObjectToJson( new { total = total, rows = dt }); } /// /// 添加备注 /// /// /// public string AddNotes(SubmitProblemFormModel model) { var ProcessId = queryDbService.AddNotes(model); return ProcessId; } #endregion } }