using PMS.BusinessModels.SmartForm; using PMS.BusinessModels.SMS; using PMS.EntityModels.SmartForm; using PMS.Interface; using PMS.Interface.MessageManage; using PMS.Interface.SmartForm; using QWPlatform.SystemLibrary; using QWPlatform.SystemLibrary.Email; using QWPlatform.SystemLibrary.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Web; using System.Web.Mvc; namespace PMS.WebUI.Controllers { public class SmartFormController : BaseController { /// /// 实例接口 /// ISmartForm SmartForm = InterfaceFactory.CreateBusinessInstance(); //推送消息 IMessageManage notice = InterfaceFactory.CreateBusinessInstance(); private static EmailServerInfo emailServerInfo; private static SmtpEmail smtpClient; private static Plugins.Email.SmtpEmail _smtpClient;//内部重写 // GET: SmartForm public ActionResult SmartIndex() { return View(); } public ActionResult AddSmartForm() { return View(); } /// /// 新增分类 /// /// public ActionResult AddClass() { return View(); } /// /// 项目填报管理 /// /// public ActionResult FillingManagement() { return View(); } /// /// 新增修改分类 /// /// /// public ActionResult AddCategory(ZNBDFL model) { ZNBDFLModel zNBDFLModel = new ZNBDFLModel(); zNBDFLModel.ID = model.ID; zNBDFLModel.上级ID = model.上级ID; zNBDFLModel.名称 = model.名称; zNBDFLModel.应用性质 = model.应用性质; zNBDFLModel.应用范围 = model.应用范围; var r= SmartForm.AddCategory(model.type, zNBDFLModel); if (r) {//保存成功 return this.ResponseJson(System.Net.HttpStatusCode.OK, "操作成功"); } else {//保存失败 return this.ResponseJson(System.Net.HttpStatusCode.InternalServerError, "操作失败"); } } /// /// 删除智能表单分类 /// /// /// public ActionResult DelCategory(ZNBDFLModel zNBDFLModel) { var msg = "删除成功!"; var r = SmartForm.DelCategory(zNBDFLModel,ref msg); if (r) {//保存成功 return this.ResponseJson(System.Net.HttpStatusCode.OK, msg); } else {//保存失败 return this.ResponseJson(System.Net.HttpStatusCode.InternalServerError, msg); } } /// /// 获取分类下来树 /// /// public ActionResult GetCategory(string id) { var list= SmartForm.GetCategory(id); var json = Strings.ObjectToJson(list); return Content(json, "application/json"); } /// /// 审核通过时,邮件需要推送附件 /// /// 记录id /// 表单id /// 项目 /// public ActionResult UploadFileInfo(string id,string BDXXID, string XM) { ViewBag.ID = id; ViewBag.BDXXID = BDXXID; ViewBag.CLR = GetCurrentUser().Name; ViewBag.XM = XM; return View(); } /// /// 保存智能表单 /// /// /// public ActionResult AddSmartFormInfo(ZNBCXX model) { ZNBCXXModel XMmodel = new ZNBCXXModel(); XMmodel.FLID = model.FLID; XMmodel.MC = model.MC; XMmodel.BT = model.BT; //XMmodel.TXTS = model.TXTS; XMmodel.TXXZ = model.TXXZ; XMmodel.CLMS = model.CLMS; XMmodel.BZ = model.BZ; XMmodel.SFTX = model.SFTX; XMmodel.TXHM = model.TXHM; XMmodel.YJTS = model.YJTS; XMmodel.SHTX = model.SHTX; XMmodel.SHTXHM = model.SHTXHM; XMmodel.SHYJTS = model.SHYJTS; XMmodel.SHBHFJ = model.SHBHFJ; ZNBCMBModel BBModel = new ZNBCMBModel(); BBModel.BDNR = HttpUtility.UrlDecode(model.BDNR); BBModel.BDCLNR = HttpUtility.UrlDecode(model.BDCLNR); BBModel.CZR= GetCurrentUser().Name; var r = SmartForm.Add(XMmodel, BBModel); if (r) {//保存成功 return this.ResponseJson(System.Net.HttpStatusCode.OK, "操作成功"); } else {//保存失败 return this.ResponseJson(System.Net.HttpStatusCode.InternalServerError, "操作失败"); } } /// /// 更新智能表单 /// /// /// public ActionResult UpdateSmartForm(ZNBCXX model) { ZNBCXXModel XMmodel = new ZNBCXXModel(); XMmodel.FLID = model.FLID; XMmodel.MC = model.MC; XMmodel.BT = model.BT; //XMmodel.TXTS = model.TXTS; XMmodel.TXXZ = model.TXXZ; XMmodel.CLMS = model.CLMS; XMmodel.BZ = model.BZ; XMmodel.SFTX = model.SFTX; XMmodel.TXHM = model.TXHM; XMmodel.YJTS = model.YJTS; XMmodel.SHTX = model.SHTX; XMmodel.SHTXHM = model.SHTXHM; XMmodel.SHYJTS = model.SHYJTS; XMmodel.SHBHFJ = model.SHBHFJ; XMmodel.ID = model.ID; XMmodel.ZT = model.ZT; ZNBCMBModel BBModel = new ZNBCMBModel(); BBModel.BDNR = HttpUtility.UrlDecode(model.BDNR); BBModel.BDCLNR = HttpUtility.UrlDecode(model.BDCLNR); BBModel.CZR = GetCurrentUser().Name; var r = SmartForm.UpdateSmartForm(XMmodel, BBModel); if (r) {//保存成功 return this.ResponseJson(System.Net.HttpStatusCode.OK, "操作成功"); } else {//保存失败 return this.ResponseJson(System.Net.HttpStatusCode.InternalServerError, "操作失败"); } } /// /// 查询数据对象并进行赋值【查询智能表单信息】 /// /// /// public ActionResult BdxxSelect(string id) { var list = SmartForm.BdxxSelect(id); var json = Strings.ObjectToJson(list); return Content(json, "application/json"); } /// /// 表单信息列表查询 /// /// /// public ActionResult BdxxSelectList(ZNBCXXModel model) { var list = SmartForm.BdxxSelectList(model); var json = Strings.ObjectToJson(list); return Content(json, "application/json"); } /// /// 复制表单 /// /// 表单id /// public ActionResult CopySmartForm(string id) { var CZR = GetCurrentUser().Name; var r = SmartForm.CopySmartForm(id, CZR); if (r) {//保存成功 return this.ResponseJson(System.Net.HttpStatusCode.OK, "操作成功"); } else {//保存失败 return this.ResponseJson(System.Net.HttpStatusCode.InternalServerError, "操作失败"); } } #region 表单填写记录 /// /// 表单信息列表查询 /// /// /// public ActionResult SelectRecordList(SelectBDTXJLModel model) { var list = SmartForm.SelectRecordList(model); var json = Strings.ObjectToJson(new { total = model.total, rows = list }); return Content(json, "application/json"); } /// /// 查询所有的分类下面【表单填写记录】 /// /// /// /// public ActionResult SelectRecordListAll(SelectBDTXJLModel model) { var list = SmartForm.SelectRecordListAll(model,"0"); var json = Strings.ObjectToJson(new { total = model.total, rows = list }); return Content(json, "application/json"); } /// /// 保存表单内容 /// /// /// public ActionResult AddRecord(BDTXJLModel model) { model.TBR = GetCurrentUser().Name; model.TBRID = GetCurrentUser().PersonID; model.QDID = GetCurrentUser().CompanyID; model.QDMC = GetCurrentUser().Company; model.BDNR = HttpUtility.UrlDecode(model.BDNR); model.BDCLNR = HttpUtility.UrlDecode(model.BDCLNR); model.BDJG = HttpUtility.UrlDecode(model.BDJG); var rs = SmartForm.AddRecord(model); if (rs) { if(model.TBZT==0) { //通知线程(邮件等) ThreadPool.QueueUserWorkItem(new WaitCallback(PushMessg), model); } return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "成功", null).ToString(), "application/json"); } else { return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "失败", null).ToString(), "application/json"); } } //填报推送 private void PushMessg(object model) { var processModel = model as BDTXJLModel; try { var dtmodel = SmartForm.BdxxSelect(processModel.BDXXID); if (dtmodel.SFTX == 1) { NotificationDto no = new NotificationDto(); no.style = "3"; no.template_code = "_irn5-4QRA2cFx7MWC0S_5AGlf1VVMXWIM1BPxi_RwQ"; var time = DateTime.Now; var coutent ="【"+ processModel.QDMC+"-"+ processModel.TBR+ "】对【" + processModel.XMMC + "】提交了【"+ dtmodel.MC+ "】"; var title = "您收到新的表单填报!"; no.template_value = "{\"first\":{\"value\":\"" + title + "\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\"" + time + "\",\"color\":\"#173177\"},\"keyword2\":{\"value\":\"" + dtmodel.MC + "\",\"color\":\"#173177\"},\"keyword3\":{\"value\":\"" + coutent + "\",\"color\":\"#173177\"},\"remark\":{\"value\":\"请登录问题管理系统进行处理。\",\"color\":\"#173177\"}}"; //no.url = "https://zlpms.zlsoft.com:8078/MobileProblem/ProblemDetail/" + ProblemID; List list = new List(); var dt= SmartForm.GetPushAccountInfo(dtmodel.TXHM); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { MessageDetailsDto mdd = new MessageDetailsDto(); mdd.接收人id = dt.Rows[i].GetValueByName("微信id"); list.Add(mdd); } no.record_items = list; notice.SendWeChartTempletMessge(no); } //邮件 //touser.Add("zp@zlsoft.cn"); //touser.Add("zxm@zlsoft.cn"); List ccuser = new List(); List touser = new List(); if (dtmodel.YJTS != null || dtmodel.YJTS != "") { var arr = dtmodel.YJTS.Split(','); for (int i = 0; i < arr.Length; i++) { touser.Add(arr[i]); } emailServerInfo = new EmailServerInfo("m.zlsoft.cn", "问题管理工具", "zljtysywpt@zlsoft.cn", "zlsoft@2019"); //实例化发送对象 "" smtpClient = new SmtpEmail(emailServerInfo); var emai = new EmailInfo(title, coutent, touser.ToArray(), ccuser.ToArray()); var user = emailServerInfo.SendEmail; var name = emailServerInfo.SendUserName; emai.FromUser(user, name); //发送邮件 smtpClient?.Send(emai); } } } catch (Exception ex) { } } /// /// 审核推送 /// /// private void AuditPushMessg(object model) { var processModel = model as BDTXJLModel; try { BDTXJLModel bdmodel = new BDTXJLModel(); bdmodel.ID = processModel.ID; var fromInfor= SmartForm.MyRecordList(bdmodel); NotificationDto no = new NotificationDto(); no.style = "3"; no.template_code = "OIE51OsXeECnoPxGgPTQ7acXybc7t1plgAbdlH-mMWE"; var time = DateTime.Now; var state = processModel.TBZT == 1 ? "通过" : "退回"; var coutent ="【" + fromInfor.FirstOrDefault().XMMC + "】填报的表单已被【" + processModel.SHR + "】" + state; var title = "表单处理结果通知!"; var color = "#173177"; if (processModel.TBZT == 1) { no.url = "https://zlpms.zlsoft.com:8078/SmartForm/MobileSmartDetailPreview/" + processModel.ID; } else { color = "#2ab8ff"; no.url = "https://zlpms.zlsoft.com:8078/SmartForm/EditMobileSmartDetail/" + processModel.ID; } no.template_value = "{\"first\":{\"value\":\"" + title + "\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\"" + time + "\",\"color\":\"#173177\"},\"keyword2\":{\"value\":\"" + coutent + "\",\"color\":\"" + color + "\"},\"remark\":{\"value\":\"点击【查看详情】立即查阅您填写的表单\",\"color\":\"#173177\"}}"; List list = new List(); var dt = SmartForm.GetSysAccountInfo(fromInfor.FirstOrDefault().TBRID); if (dt != null && dt.Rows.Count > 0) { //邮件 List ccuser = new List(); List touser = new List(); for (int i = 0; i < dt.Rows.Count; i++) { MessageDetailsDto mdd = new MessageDetailsDto(); if(dt.Rows[i].GetValueByName("微信id")!=null) { mdd.接收人id = dt.Rows[i].GetValueByName("微信id"); list.Add(mdd); } if (dt.Rows[i].GetValueByName("邮箱") != null) { touser.Add(dt.Rows[i].GetValueByName("邮箱")); } } no.record_items = list; if(no.record_items.Count>0) { notice.SendWeChartTempletMessge(no); } if(touser.Count>0) { emailServerInfo = new EmailServerInfo("m.zlsoft.cn", "问题管理工具", "zljtysywpt@zlsoft.cn", "zlsoft@2019"); //实例化发送对象 "" smtpClient = new SmtpEmail(emailServerInfo); var emai = new EmailInfo(title, coutent, touser.ToArray(), ccuser.ToArray()); var user = emailServerInfo.SendEmail; var name = emailServerInfo.SendUserName; emai.FromUser(user, name); //发送邮件 smtpClient?.Send(emai); } } } catch (Exception ex) { } } /// /// 更新记录 /// /// /// public ActionResult UpdateRecord(BDTXJLModel model) { model.SHR = GetCurrentUser().Name; model.SHRID = GetCurrentUser().PersonID; model.TBR = GetCurrentUser().Name; model.QDID = GetCurrentUser().CompanyID; model.QDMC = GetCurrentUser().Company; //处理页面有html model.BDJG = HttpUtility.UrlDecode(model.BDJG); model.BDCLJG = HttpUtility.UrlDecode(model.BDCLJG); var rs = SmartForm.UpdateRecord(model, int.Parse(model.BZ));//这个地方的备注传界面操作状态 if (rs) { if (model.BZ=="3")//退回重新填报 { //通知线程(邮件等) ThreadPool.QueueUserWorkItem(new WaitCallback(PushMessg), model); } else if(model.BZ=="2") { //审核通过通知填报人 ThreadPool.QueueUserWorkItem(new WaitCallback(AuditPushMessg), model); } return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "成功", null).ToString(), "application/json"); } else { return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "失败", null).ToString(), "application/json"); } } /// /// 审核推送带附件 /// /// /// public ActionResult AuditAttachmentPush(EmailPush emailPush) { BDTXJLModel model =new BDTXJLModel(); model.SHR = GetCurrentUser().Name; model.SHRID = GetCurrentUser().PersonID; model.TBR = GetCurrentUser().Name; model.QDID = GetCurrentUser().CompanyID; model.QDMC = GetCurrentUser().Company; model.TBZT = 1; model.BZ ="2"; model.ID = emailPush.ID; //处理页面有html model.BDJG = HttpUtility.UrlDecode(model.BDJG); model.BDCLJG = HttpUtility.UrlDecode(model.BDCLJG); var rs = SmartForm.UpdateRecord(model, int.Parse(model.BZ));//这个地方的备注传界面操作状态 if (rs) { //审核通过通知公司相关人员 ThreadPool.QueueUserWorkItem(new WaitCallback(AuditEnclosurePushMessg), emailPush); return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "成功", null).ToString(), "application/json"); } else { return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "失败", null).ToString(), "application/json"); } } /// /// 审核带附件推送 /// /// private void AuditEnclosurePushMessg(object model) { var processModel = model as EmailPush; try { var dtmodel = SmartForm.BdxxSelect(processModel.BDXXID); if (dtmodel.SHTX == 1) { NotificationDto no = new NotificationDto(); no.style = "3"; no.template_code = "OIE51OsXeECnoPxGgPTQ7acXybc7t1plgAbdlH-mMWE"; var time = DateTime.Now; var color = "#173177"; no.url = "https://zlpms.zlsoft.com:8078/SmartForm/MobileSmartDetailPreview/" + processModel.ID; no.template_value = "{\"first\":{\"value\":\"" + processModel.TSBT + "\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\"" + time + "\",\"color\":\"#173177\"},\"keyword2\":{\"value\":\"" + processModel.TSNR + "\",\"color\":\"" + color + "\"},\"remark\":{\"value\":\"点击【查看详情】立即查阅您填写的表单\",\"color\":\"#173177\"}}"; //邮件 List ccuser = new List(); List touser = new List(); List list = new List(); //将当前填报人加入推送消息中 BDTXJLModel bdmodel = new BDTXJLModel(); bdmodel.ID = processModel.ID; var fromInfor = SmartForm.MyRecordList(bdmodel); var nowdt = SmartForm.GetSysAccountInfo(fromInfor.FirstOrDefault().TBRID); if (nowdt != null && nowdt.Rows.Count > 0) { for (int i = 0; i < nowdt.Rows.Count; i++) { MessageDetailsDto mdd = new MessageDetailsDto(); if (nowdt.Rows[i].GetValueByName("微信id") != null) { mdd.接收人id = nowdt.Rows[i].GetValueByName("微信id"); list.Add(mdd); } if (nowdt.Rows[i].GetValueByName("邮箱") != null) { touser.Add(nowdt.Rows[i].GetValueByName("邮箱")); } } } //将审核人员添加到推送消息列表 var dt = SmartForm.GetPushAccountInfo(dtmodel.TXHM); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { MessageDetailsDto mdd = new MessageDetailsDto(); if (dt.Rows[i].GetValueByName("微信id") != null) { mdd.接收人id = dt.Rows[i].GetValueByName("微信id"); list.Add(mdd); } } no.record_items = list; if (no.record_items.Count > 0) { notice.SendWeChartTempletMessge(no); } } //邮件推送 if(dtmodel.SHYJTS!=null || dtmodel.SHYJTS!="") { var arr = dtmodel.SHYJTS.Split(','); for (int i = 0; i < arr.Length; i++) { touser.Add(arr[i]); } if (touser.Count > 0) { List AttachFiles = new List(); List AttachFilesArray = new List(); if (processModel.File!=null) { foreach (var item in processModel.File) { Plugins.Email.FileArray _fileArray = new Plugins.Email.FileArray(); byte[] imageBytes = Convert.FromBase64String(item.data.Replace("data:image/jpeg;base64,", "").Replace("data:image/png;base64,", "").Replace("data:image/gif;base64,", "").Replace("data:image/jpg;base64,", "")); _fileArray.filesBate = imageBytes; _fileArray.filesName = item.name; AttachFilesArray.Add(_fileArray); } } var _emailServerInfo = new Plugins.Email.EmailServerInfo("m.zlsoft.cn", "问题管理工具", "zljtysywpt@zlsoft.cn", "zlsoft@2019"); //实例化发送对象 "" var _smtpClient = new Plugins.Email.SmtpEmail(_emailServerInfo); var emai = new Plugins.Email.EmailInfo(processModel.TSBT, processModel.TSNR, touser.ToArray(), ccuser.ToArray(), AttachFiles, AttachFilesArray); var user = _emailServerInfo.SendEmail; var name = _emailServerInfo.SendUserName; emai.FromUser(user, name); //发送邮件 _smtpClient?.Send(emai); } } } } catch (Exception ex) { } } #region 智能表单 /// /// 智能表单预览 /// /// public ActionResult SmarView() { return View(); } //PC端新增智能表单 public ActionResult PcSmartFormList(string id, string xmid,string xmmc) { ViewBag.ID = id; ViewBag.XMID = xmid; ViewBag.XMMC = xmmc; return View(); } public ActionResult EditPcSmartFormList(string id) { ViewBag.ID = id; return View(); } #endregion #endregion #region 移动端智能表单 public ActionResult MobileSmart() { return View(); } public ActionResult MobileSmartDetail(string id) { ViewBag.ID = id; return View(); } /// /// 我的填写 /// /// /// public ActionResult MobileMySmart() { ViewBag.TBRID = GetCurrentUser().PersonID; return View(); } /// /// 我的填写记录 /// /// /// public ActionResult MyRecordList(BDTXJLModel model) { if(model.TBRID != "-1") { model.TBRID = GetCurrentUser().PersonID; } else { model.TBRID = ""; } var list = SmartForm.MyRecordList(model); var json = Strings.ObjectToJson(list); return Content(json, "application/json"); } /// /// 表单预览 /// /// public ActionResult MobileSmartDetailPreview(string id) { ViewBag.ID = id; return View(); } /// /// 编辑表单记录 /// /// /// public ActionResult EditMobileSmartDetail(string id) { ViewBag.ID = id; return View(); } #endregion } }