using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Web; using System.Web.Mvc; using DSWeb.Areas.CommMng.DAL; using DSWeb.Areas.CommMng.Models; using DSWeb.Areas.OA.Models.WorkFlow; using DSWeb.Areas.Import.Models.XXH; using DSWeb.TruckMng.Helper; using DSWeb.TruckMng.Comm.Cookie; using Dingtalk; using System.IO; using System.Net.Http; using System.Text; using DSWeb.Areas.MvcShipping.Job; using System.Runtime.Caching; using DSWeb.Areas.MvcShipping.Models.Message.VGM; using DSWeb.Areas.MvcShipping.Helper; using HcUtility.Comm; using DSWeb.MvcShipping.DAL.MsSysParamSet; using NPOI.SS.Formula.Functions; using sun.security.krb5.@internal.crypto; namespace DSWeb.Areas.CommMng.Controllers { [JsonRequestBehavior] public class WorkFlowController : Controller { // // GET: /Import/XXH public ActionResult Index() { return View(); } // // GET: /Import/XXH/Edit public ActionResult Edit() { return View(); } //提交审核 //开启工作流运行流程,向workflow_Using表中插入数据。 /* public ContentResult WorkFlowStart(string WorkFlowName, string BSNO, string USERID) { //var _count = 0; //var corpid = Convert.ToString(Session["COMPANYID"]); //var USERID = Convert.ToString(Session["USERID"]); //var DEPTGID = Convert.ToString(Session["DEPTGID"]); var Result = WorkFlowDAL.WorkFlowStart(WorkFlowName,BSNO, USERID); var json = JsonConvert.Serialize( new { Success = Result.Success, Message = Result.Message,totalCount=Result.totalCount }); return new ContentResult() { Content = json }; }*/ //撤回提交 public ContentResult WrokFlowReset(string WorkFlowName, string BSNO,string USERID) { //var corpid = Convert.ToString(Session["COMPANYID"]); var Result = WorkFlowDAL.WorkFlowReset(WorkFlowName, BSNO, USERID); var json = JsonConvert.Serialize( new { Success = Result.Success, Message = Result.Message, totalCount = Result.totalCount }); return new ContentResult() { Content = json }; } //通过工作流名称和用户名称获取该用户工作流ID public WorkFlowmb GetWorkFlowID(string WorkFlowName) { //workflow.gid workflow_step.gid,userid //var DEPTGID = Convert.ToString(Session["DEPTGID"]); var UserID = Convert.ToString(CookieConfig.GetCookie_UserId(Request)); var _r = WorkFlowDAL.GetWorkFlowmb(WorkFlowName, UserID); WorkFlowmb head = new WorkFlowmb(); if (_r.Success) head = (WorkFlowmb)_r.Data; return head; } //通过工作流名称获取该用户工作流step public JsonResult GetWorkFlowStep(string WorkFlowName) { //workflow.gid workflow_step.gid,userid var OrgCode = Convert.ToString(CookieConfig.GetCookie_OrgCode(Request)); var UserID = Convert.ToString(CookieConfig.GetCookie_UserId(Request)); var evList = WorkFlowDAL.GetWorkFlowStep(WorkFlowName, UserID); if (evList.Count == 0) { return Json(new { success = false }); } else { return Json(new { success = true, data = evList.ToList() }); } } //获取工作流当前状态 public JsonResult GetWorkFlowBSNO(string WorkFlowName, string STEPNO) { //workflow.gid workflow_step.gid,userid var USERID = Convert.ToString(CookieConfig.GetCookie_UserId(Request)); //由某一工作流环节调取,由本方法获取该userid,该stepid所能操作的bsno列表,并返回。 //Workflow_usingmb head = null; var WorkFlowID = GetWorkFlowID(WorkFlowName).GID; if (WorkFlowID == null) { return Json(new { success = false, Message = "未找到相应工作流" }); } List evList = WorkFlowDAL.GetWorkFlowBSNOList(WorkFlowID, System.Int32.Parse(STEPNO), USERID); if (evList.Count == 0) { return Json(new { success = false }); } else { return Json(new { success = true, data = evList.ToList() }); } } //获取某项业务的工作流当前状态 public JsonResult GetBSNOWorkFlowState(string WORKFLOWID, string BSNO) { var USERID = Convert.ToString(CookieConfig.GetCookie_UserId(Request)); //由某一工作流环节调取,由本方法获取该userid,该stepid所能操作的bsno列表,并返回。 //Workflow_usingmb head = null; //var WorkFlowID = GetWorkFlowID(WorkFlowName).GID; if (WORKFLOWID == null) { return Json(new { success = false }); } List evList = WorkFlowDAL.GetBSNOWorkFlow(WORKFLOWID, BSNO); if (evList.Count == 0) { return Json(new { success = false }); } else { return Json(new { success = true, data = evList.ToList() }); } } /// /// * /// /// /// /* public Resultmb GetNeedAudit(string GID) { //HTmb head = null; var _count = WorkFlowDAL.GetNeedAudit(GID); var _result = new Resultmb(); if (_count == 0) { _result.Success = true; } else { _result.Success = false; _result.Message = "不能修改,还有" + _count.ToString() + "条业务等待此步骤审核,请将这些业务审核通过或完全撤回后再修改"; } return _result; } */ /// /// /// /// /// public ContentResult GetCanChange(string GID) { //HTmb head = null; var _CanChange = WorkFlowDAL.GetCanChange(GID); var _result = new Resultmb(); if (_CanChange.ChangeStep==false) { _result.Success = false; _result.Message = "不能修改,还有业务等待此步骤审核,请将这些业务审核通过或完全撤回后再修改"; } else { _result.Success = true; } var jsonRespose = new JsonResponse { Success = _result.Success, Message = _result.Message, //Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'") }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult GetCanChange_UserPath(string USERID,string TYPENO,string NewWorkFlowID) { //HTmb head = null; var _result = WorkFlowDAL.GetCanChange_UserPath(USERID, TYPENO, NewWorkFlowID); var Result = new Resultmb(); if (_result == false) { Result.Success = false; Result.Message = "不能修改,还有业务等待此步骤审核,请将这些业务审核通过或完全撤回后再修改"; } else { Result.Success = true; } var jsonRespose = new JsonResponse { Success = Result.Success, Message = Result.Message, //Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'") }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } /// /// 钉钉审批 返回解析 /// /// /// /// /// [System.Web.Mvc.HttpPost] public string DingdingCallback(string signature, string timestamp, string nonce) { //JeffSoft.Logger.Error("DingdingCallback Success:" + signature + "," + timestamp + ""); //第一部分 //这两句代码是为了接收body体中传入的加密json串 StreamReader sr = new StreamReader(Request.InputStream, Encoding.UTF8); var strJson = new StringBuilder(); string line = null; while (((line = sr.ReadLine())) != null) { strJson.Append(line); } //BasicDataRefDAL.SaveLog("["+signature+"]["+ timestamp+"]["+ nonce+"]"+"["+ strJson + "]", "admin", "钉钉回调", "保存"); //反序列化json串拿去加密字符串 var objRtn = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(strJson.ToString(), new { encrypt = "" }); string ever = objRtn.encrypt; var appname = MsSysParamSetDAL.GetSysParamValue("DingTalkAppName"); //var 钉钉应用 = DingTalkApp.GetDingTalkApp("诚锐东胜对接"); var 钉钉应用 = DingTalkApp.GetDingTalkApp(appname); //钉钉应用=DingTalkProcess.GetDingTalkProcessByProcessCode(callbackinfo.processCode); //实例化钉钉解密类构造参数为对应的 应用中的token、aes_key、AppKey值 DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor(钉钉应用.token, 钉钉应用.aes_key, 钉钉应用.appkey); //定义字符串接收解密后的值 string text = dingTalkEncryptor.getDecryptMsg(signature, timestamp, nonce, ever); //JeffSoft.Logger.Error("dingTalkEncryptor.getDecryptMsg:" + text + ""); BasicDataRefDAL.SaveLog( text , "admin", "钉钉回调", "保存1"); var callbackinfo = JsonConvert.Deserialize(text); var 钉钉审批 = 钉钉应用.GetDingTalkProcessByProcessCode(callbackinfo.processCode); 钉钉审批.SaveCallBack(callbackinfo); //var objRtn2 = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(text.ToString(), new { EventType = "" }); //var _jsstr = JsonConvert.Serialize(objRtn2); //BasicDataRefDAL.SaveLog(_jsstr, "admin", "钉钉回调", "保存2"); //取出事件类型字段 //JeffSoft.Logger.Error("DingdingCallback Success,EventType:" + EventType + ""); //第二部分 // { //判断事件类型是否是日程事件 if ("bpms_instance_change" == callbackinfo.EventType) { var DingCallBackMsg = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(text.ToString(), new DingCallBackMsg()); var DDtitle = DingCallBackMsg.title; var DDresult = DingCallBackMsg.result; var mes = string.Format("bpms_instance_change Success,title:{0},result:{1}", DDtitle, DDresult); 钉钉审批.DoDeal(); //if () //result = DingTalkHelper.DingTalk_Instanceinfo("i0P82FAHT_G9TWJmavxGdg03131673000830"); //var _jsstr3 = JsonConvert.Serialize(objRtn2); //BasicDataRefDAL.SaveLog(_jsstr, "admin", "钉钉回调", "保存3"); //JeffSoft.Logger.Error(mes); } //第三部分 //返回加密字符串 var msg = dingTalkEncryptor.getEncryptedMap("success"); var msg_signature = msg["msg_signature"]; var encrypt = msg["encrypt"]; var timeStamp = msg["timeStamp"]; var nonce1 = msg["nonce"]; var v = new { msg_signature = msg["msg_signature"], encrypt = msg["encrypt"], timeStamp = msg["timeStamp"], nonce = msg["nonce"], }; //var obj = new { success = r }; // return Json(obj); var data = Newtonsoft.Json.JsonConvert.SerializeObject(v); return data; } [System.Web.Mvc.HttpPost] public string Test_DingdingCallback(string text) { var result = ""; try { var _r = new DBResult(); var appname = MsSysParamSetDAL.GetSysParamValue("DingTalkAppName"); //var 钉钉应用 = DingTalkApp.GetDingTalkApp("诚锐东胜对接"); var 钉钉应用 = DingTalkApp.GetDingTalkApp(appname); //钉钉应用=DingTalkProcess.GetDingTalkProcessByProcessCode(callbackinfo.processCode); //实例化钉钉解密类构造参数为对应的 应用中的token、aes_key、AppKey值 DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor(钉钉应用.token, 钉钉应用.aes_key, 钉钉应用.appkey); //定义字符串接收解密后的值 //JeffSoft.Logger.Error("dingTalkEncryptor.getDecryptMsg:" + text + ""); BasicDataRefDAL.SaveLog(text, "admin", "钉钉回调", "测试1"); var callbackinfo = JsonConvert.Deserialize(text); var 钉钉审批 = 钉钉应用.GetDingTalkProcessByProcessCode(callbackinfo.processCode); 钉钉审批.SaveCallBack(callbackinfo); // { //判断事件类型是否是日程事件 if ("bpms_instance_change" == callbackinfo.EventType) { var DingCallBackMsg = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(text.ToString(), new DingCallBackMsg()); var DDtitle = DingCallBackMsg.title; var DDresult = DingCallBackMsg.result; var mes = string.Format("bpms_instance_change Success,title:{0},result:{1}", DDtitle, DDresult); _r= 钉钉审批.DoDeal(); //if () //result = DingTalkHelper.DingTalk_Instanceinfo("i0P82FAHT_G9TWJmavxGdg03131673000830"); //var _jsstr3 = JsonConvert.Serialize(objRtn2); //BasicDataRefDAL.SaveLog(_jsstr, "admin", "钉钉回调", "保存3"); //JeffSoft.Logger.Error(mes); } var data = Newtonsoft.Json.JsonConvert.SerializeObject(_r); return data; } catch(Exception ex) { return ex.Message; } } public class CallBackInfo { /// /// /// public string processInstanceId { get; set; } /// /// /// public string corpId { get; set; } /// /// /// public string EventType { get; set; } /// /// /// public string businessId { get; set; } /// /// 邓羽提交的入货通知 /// public string title { get; set; } /// /// /// public string type { get; set; } /// /// /// public long? createTime { get; set; } /// /// /// public string processCode { get; set; } /// /// /// public string bizCategoryId { get; set; } /// /// /// public string businessType { get; set; } /// /// /// public string staffId { get; set; } /// /// /// public long? taskId { get; set; } } } }