You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/CommMng/Controllers/WorkFlowController.cs

446 lines
16 KiB
C#

3 years ago
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;
3 years ago
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<WorkFlow_Usingmb> 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<BSNOWorkFlowStatemb> evList = WorkFlowDAL.GetBSNOWorkFlow(WORKFLOWID, BSNO);
if (evList.Count == 0)
{
return Json(new { success = false });
}
else
{
return Json(new { success = true, data = evList.ToList() });
}
}
/// <summary>
/// *
/// </summary>
/// <param name="GID"></param>
/// <returns></returns>
/*
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;
}
*/
/// <summary>
///
/// </summary>
/// <param name="GID"></param>
/// <returns></returns>
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) };
}
/// <summary>
/// 钉钉审批 返回解析
/// </summary>
/// <param name="signature"></param>
/// <param name="timestamp"></param>
/// <param name="nonce"></param>
/// <returns></returns>
2 years ago
[System.Web.Mvc.HttpPost]
public string DingdingCallback(string signature, string timestamp, string nonce)
{
2 years ago
BasicDataRefDAL.SaveLog(nonce, "admin", "钉钉回调", "保存1");
//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);
}
2 years ago
//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 + "");
2 years ago
BasicDataRefDAL.SaveLog( text , "admin", "钉钉回调", "保存1");
var callbackinfo = JsonConvert.Deserialize<CallBackInfo>(text);
var = .GetDingTalkProcessByProcessCode(callbackinfo.processCode);
.SaveCallBack(callbackinfo);
2 years ago
//var objRtn2 = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(text.ToString(), new { EventType = "" });
2 years ago
//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);
2 years ago
.DoDeal();
//if ()
//result = DingTalkHelper.DingTalk_Instanceinfo("i0P82FAHT_G9TWJmavxGdg03131673000830");
//var _jsstr3 = JsonConvert.Serialize(objRtn2);
//BasicDataRefDAL.SaveLog(_jsstr, "admin", "钉钉回调", "保存3");
2 years ago
//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);
2 years ago
return data;
}
3 years ago
[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<CallBackInfo>(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
{
/// <summary>
///
/// </summary>
public string processInstanceId { get; set; }
/// <summary>
///
/// </summary>
public string corpId { get; set; }
/// <summary>
///
/// </summary>
public string EventType { get; set; }
/// <summary>
///
/// </summary>
public string businessId { get; set; }
/// <summary>
/// 邓羽提交的入货通知
/// </summary>
public string title { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public long? createTime { get; set; }
/// <summary>
///
/// </summary>
public string processCode { get; set; }
/// <summary>
///
/// </summary>
public string bizCategoryId { get; set; }
/// <summary>
///
/// </summary>
public string businessType { get; set; }
/// <summary>
///
/// </summary>
public string staffId { get; set; }
/// <summary>
///
/// </summary>
public long? taskId { get; set; }
}
3 years ago
}
}