public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } try { string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); //json转Hashtable Object jgobj = ToolsClass.DeserializeObject(CsJson); Hashtable returnhash = jgobj as Hashtable; if (returnhash == null) { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } string path = context.Request.Path.Replace("Approval/GetBillName.ashx", "billname"); string path1 = context.Request.Path.Replace("Approval/GetBillName.ashx", "getbillclassnode"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); string sign1 = ToolsClass.md5(signUrl + path1 + "Romens1/DingDing2" + path1, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + returnhash["Sign"].ToString() + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != returnhash["Sign"].ToString() && sign1 != returnhash["Sign"].ToString()) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } if (returnhash.Contains("SearchAall")) { SearchAall = returnhash["SearchAall"].ToString(); if (SearchAall == "") { context.Response.Write("{\"errmsg\":\"SearchAall不允许为空(DD2001)\",\"errcode\":1}"); return; } } //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("获取审批类型日志", "\r\n获取审批类型信息入参:" + CsJson.ToString() + "\r\n"); } //获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } //获取流程类型 if (SearchAall == "1") { sql = "select BillClassid,BillName,BillLogoUrl,BillUrl,VisibleRange from BillClass"; obj = da.GetDataTable(sql); dt = obj as DataTable; rJson.Append("{\"errmsg\":\"ok\",\"errcode\":0,\"count\":").Append(dt.Rows.Count).Append(",\"data\":["); if (dt.Rows.Count > 0) { for (int x = 0; x < dt.Rows.Count; x++) { if (x > 0) { rJson.Append(","); } rJson.Append("{"); for (int y = 0; y < dt.Columns.Count; y++) { if (y > 0) { rJson.Append(","); } rJson.Append("\"").Append(dt.Columns[y].ColumnName).Append("\":\"").Append(dt.Rows[x][dt.Columns[y].ColumnName].ToString()).Append("\""); } rJson.Append("}"); } } rJson.Append("]}"); } //获取现在已保存的流程信息节点 if (SearchAall == "2") { ClassType = returnhash["ClassType"].ToString(); if (ClassType == "") { context.Response.Write("{\"errmsg\":\"ClassType不允许为空(DD2001)\",\"errcode\":1}"); return; } sql = ""; sql = $"select ClassRuCan from BillClass where BillClassid ='{ClassType}' "; obj = da.GetValue(sql).ToString(); rJson.Append(obj); } context.Response.Write(rJson.Replace(" ", "")); if (isWrite == "1") { ToolsClass.TxtLog("获取审批类型日志", "\r\n获取审批类型信息出参:" + rJson.ToString() + "\r\n"); } return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "\",\"errcode\":1}"); return; } }
private string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 string connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); SqlHelper = new BankDbHelper.SqlHelper("SqlServer", connectionString); string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret string AppWyy = ToolsClass.GetConfig("AppWyy"); string[] ScList = AppWyy.Split('$'); string agentId = ScList[0].ToString(); string corpId = ScList[1].ToString(); string appKey = ScList[2].ToString(); string appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n申请审批入参:" + CsJson + "\r\n"); } string IsLocalHost = "0"; //前端传入数据 TravelApprovalMul traApprClass = new TravelApprovalMul(); traApprClass = (TravelApprovalMul)JsonConvert.DeserializeObject(CsJson, typeof(TravelApprovalMul)); string result = string.Empty; IsLocalHost = traApprClass.IsLocalHost == null ? "0" : traApprClass.IsLocalHost; string path = context.Request.Path.Replace("Approval/CLFBXSP.ashx", "clfbxspmul"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + traApprClass.Sign + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != traApprClass.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } GetMulParams getMulParams = new GetMulParams(); #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); string access_token = tokenClass.access_token; int errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } string audiName = userXqClass.name; #endregion 获取用户详情 #region 获取用户guid Sql = $"select top 1 a.GUID,b.TotalAmount,b.OffDay from operators a left join (select sum(TotalAmount) TotalAmount, sum(OffDay) OffDay from ExpetravDetail where billno = '[申请号]' group by billno) b on 1 = 1 where a.code = '[工号]'"; Sql = Sql.Replace("[申请号]", traApprClass.BillNo).Replace("[工号]", userXqClass.jobnumber); obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; string AuditingGuid = dt.Rows[0]["GUID"].ToString(); #endregion 获取用户guid //判断当前是流程节点中的哪个流程 Sql = $"select count( DISTINCT NodeNumber) NodeNumber from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; //得到当前流程节点的数量 string nodeNumber = da.GetValue(Sql).ToString(); //得到当前流程信息 NodeInfo[] NodeInfo = (NodeInfo[])JsonConvert.DeserializeObject(da.GetValue($"select ProcessNodeInfo from ExpeTrav where BillNo='{traApprClass.BillNo}'").ToString(), typeof(NodeInfo[])); XXTZ xxtzClass2 = new XXTZ(); StringBuilder piddept = new StringBuilder(); string sql = ""; DataTable logComments = new DataTable(); StringBuilder logcoments = new StringBuilder(); if (traApprClass.IsSp == "1") { audiIdea = "同意"; } else if (traApprClass.IsSp == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } //获取当前单号的发起人和待报销人 string fqrall = traApprClass.DDOperatorId; var fqr = da.GetDataTable($"select DDOperatorId,InsteadOperatorGuid,IsSp from ExpeTrav where BillNo = '{traApprClass.BillNo}'"); if (fqr.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"当前单据已撤回\",\"errcode\":1}"); return; } else if (fqr.Rows[0]["IsSp"].ToString() == "3") { context.Response.Write("{\"errmsg\":\"当前单据已撤回\",\"errcode\":1}"); return; } if (fqr.Rows[0]["InsteadOperatorGuid"].ToString() != fqrall) { fqrall = fqrall + "," + fqr.Rows[0]["InsteadOperatorGuid"].ToString(); } //判断当前人是否已经审批过 Sql = $"select * from ApprovalComments where ApprovalStatus='0' and BillNo ='{traApprClass.BillNo}' and ApprovalID='{userXqClass.jobnumber}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; ToolsClass.TxtLog("差旅费申请审批日志", "\r\n查询当前人的审批节点" + Sql + "\r\n"); if (da.GetDataTable(Sql).Rows.Count == 0) { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + JsonConvert.SerializeObject(new PublicResult { errcode = "1", errmsg = "当前单据您已经审批过,请勿点击太快或者重复提交!" })); context.Response.Write(JsonConvert.SerializeObject(new PublicResult { errcode = "1", errmsg = "当前单据您已经审批过,请勿点击太快或者重复提交!" })); return; } //如果审批人意见为同意 if (audiIdea == "同意" || audiIdea == "抄送") { try { bool processIsEnd = false; processIsEnd = CommonHelper.SaveComments(traApprClass, userXqClass, nodeNumber, context, ddUrl, "差旅费申请审批日志", out result); //可以给下个人发送消息 if (processIsEnd) //如果当前流程节点走完 { //判断当前单号是否已经结束 sql = ""; sql = $"select ISSP from ExpeTrav where BillNo ='{traApprClass.BillNo}'"; if (da.GetValue(sql).ToString() != "0") { if (IsLocalHost == "0") { result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); } else { result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); } return; } //判断是否是根结点,判断数量(去重)是否小于流程的长度 //是否是最后一个流程 if (int.Parse(nodeNumber) < NodeInfo.Length) { NodeInfoDetailPerson[] NodeInfodetailPeople = NodeInfo[int.Parse(nodeNumber)].NodeInfoDetails[0].Persons; //插入相应的信息到comments表中 sqlList.Clear(); for (int i = 0; i < NodeInfodetailPeople.Length; i++) { sqlTou.Clear(); sqlTou.Append("insert into ApprovalComments(CommentsId,BillClassId,BillNo,ApprovalID,ApprovalName,ApprovalComments,ApprovalStatus,AType,ApprovalDate,IsAndOr,IsLeader,PersonType,NodeNumber) values('") .Append(Guid.NewGuid().ToString()).Append("','") .Append(traApprClass.BillClassId).Append("','") .Append(traApprClass.BillNo).Append("','") .Append(NodeInfodetailPeople[i].PersonId).Append("','") .Append(NodeInfodetailPeople[i].PersonName).Append("','")//内部数据库用户GUID .Append("").Append("','") .Append("0").Append("','") .Append(NodeInfodetailPeople[i].AType).Append("','") .Append(DateTime.Now).Append("','") .Append(NodeInfo[int.Parse(nodeNumber)].NodeInfoDetails[0].IsAndOr).Append("','") .Append(NodeInfo[int.Parse(nodeNumber)].NodeInfoDetails[0].IsLeader).Append("','") .Append(NodeInfo[int.Parse(nodeNumber)].NodeInfoType).Append("','") .Append(int.Parse(nodeNumber) + 2).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n操作ApprovalComments表:" + sqlTou.ToString() + "\r\n"); } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存多级流程差旅费报销审批节点信息出错(DD6002)\",\"errcode\":1}"); return; } //获取下个节点的人员信息 for (int i = 0; i < NodeInfodetailPeople.Length; i++) { if (i > 0) { piddept.Append(","); } //判断传空 if (NodeInfodetailPeople[i].PersonId != "") { sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'"; piddept.Append(da.GetValue(sql).ToString()); } } //给申请人发送审批意见 给下个节点的人员发送目前为止的审批状态及意见,给之前的人也发 //获取现在的审批意见 sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; logComments = da.GetDataTable(sql); //"【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; for (int i = 0; i < logComments.Rows.Count; i++) { if (i > 0) { logcoments.Append(","); } //piddept.Append(","); sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{logComments.Rows[i]["ApprovalID"].ToString()}'"; //piddept.Append(da.GetValue(sql).ToString()); logcoments.Append(logComments.Rows[i]["ApprovalName"].ToString() + ":" + logComments.Rows[i]["ApprovalComments"].ToString()); } //&AType={NodeInfodetailPeople[0].AType} urlcsjson = ddUrl + $"/clfui/shenpi/index.html?billno={traApprClass.BillNo}&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"金额: " + dt.Rows[0]["TotalAmount"].ToString() + "¥ 调休: " + dt.Rows[0]["OffDay"].ToString() + "天\r\n申请人: " + traApprClass.OperatorName + "【差旅费】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n发送通知调用钉钉api入参:" + CsJson + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的差旅费报销审批消息通知失败(DD6004)\",\"errcode\":1}"); return; } sql = $"update ExpeTrav set HangState = '0',HangDDIDs = '' where billno = '{traApprClass.BillNo}'"; da.ExecSql(sql); TaskFactory taskFactory = new TaskFactory(); //如果下个是抄送人 if (NodeInfo[int.Parse(nodeNumber)].NodeInfoType == "3") { //根据数据开启多个线程调用审批接口 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "clfbxspmul"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = traApprClass.BillNo, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsSp = "3", DDOperatorId = traApprClass.DDOperatorId, OperatorName = traApprClass.OperatorName, BillClassId = traApprClass.BillClassId, Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } }); } if (NodeInfo[int.Parse(nodeNumber)].NodeInfoType == "2") { DataRow[] dataRows = null; sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}' and ApprovalStatus ='1'"; logComments = da.GetDataTable(sql); //如果下个环节中的人在之前已同意,自动调用此接口同意完成审批 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { dataRows = logComments.Select("ApprovalID ='" + NodeInfodetailPeople[i].PersonId + "'"); //如果之前已经同意或者是发起人 if (dataRows.Length != 0 || da.GetValue($"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'").ToString() == traApprClass.DDOperatorId) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "clfbxspmul"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = traApprClass.BillNo, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsSp = "1", DDOperatorId = traApprClass.DDOperatorId, OperatorName = traApprClass.OperatorName, BillClassId = traApprClass.BillClassId, AuditingIdea = "同意", Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } } }); } } //如果是最后一级 //给申请人发送审批意见 给之前的人发 //获取现在的审批意见 else { //更新单据消息id与返回内容 Sql = "update EXPETRAV set IsSp='1' where billno='" + traApprClass.BillNo + "'"; if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n更新EXPETRAV表:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #region 调用审核存储过程 billno = traApprClass.BillNo; keyValuePairs = CommonHelper.sqlPro(billno, billTypeNo, AuditingGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); Sql = "update EXPETRAV set IsSp='0' where billno='" + traApprClass.BillNo + "'"; obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批状态出错(DD6006)\",\"errcode\":1}"); return; } Sql = $"update ApprovalComments set ApprovalComments='',Urls='',ApprovalStatus='0',ApprovalDate='{DateTime.Now}',DDMessageId='' where BillNo ='{traApprClass.BillNo}' and ApprovalID='{userXqClass.jobnumber}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; ToolsClass.TxtLog("差旅费申请审批日志", "\r\n存储过程报错后执行语句:" + sql + "\r\n" + Sql); SqlHelper.ExecSql(Sql); context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); return; } #endregion 调用审核存储过程 sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; logComments = da.GetDataTable(sql); //"【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; for (int i = 0; i < logComments.Rows.Count; i++) { if (i > 0) { logcoments.Append(","); //piddept.Append(","); } sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{logComments.Rows[i]["ApprovalID"].ToString()}'"; //piddept.Append(da.GetValue(sql).ToString()); logcoments.Append(logComments.Rows[i]["ApprovalName"].ToString() + ":" + logComments.Rows[i]["ApprovalComments"].ToString()); } urlcsjson = ddUrl + $"/clfui/shenpi/index.html?billno={traApprClass.BillNo}&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"金额: " + dt.Rows[0]["TotalAmount"].ToString() + "¥ 调休: " + dt.Rows[0]["OffDay"].ToString() + "天\r\n申请人: " + traApprClass.OperatorName + "【差旅费】\r\n审批意见: " + logcoments.ToString() + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n发送通知调用钉钉api入参:" + CsJson + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的差旅费报申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } } } else { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n不给下个人发消息???:" + result + "\r\n"); context.Response.Write(result); return; } //var resultgetmul = ; if (IsLocalHost == "0") { result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); } else { result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); } return; } catch (Exception ex) { Sql = $"update ApprovalComments set ApprovalComments='',Urls='',ApprovalStatus='0',ApprovalDate='{DateTime.Now}',DDMessageId='' where BillNo ='{traApprClass.BillNo}' and ApprovalID='{userXqClass.jobnumber}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; SqlHelper.ExecSql(Sql); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "-1", errmsg = $"单据审批失败,失败原因{ex.Message + ex.StackTrace}" })); context.Response.End(); } } //如果是已驳回,给操作人发送通知,将意见及日期保存到ApprovalComments表,并改变状态,,改变出差申请表中的状态,改为2,代表已驳回 if (audiIdea == "驳回") { //将意见及日期保存到ApprovalComments表,并改变状态 Sql = ""; Sql = $"update ApprovalComments set ApprovalComments='{traApprClass.AuditingIdea}',Urls='{JsonConvert.SerializeObject(traApprClass.Urls)}',ApprovalStatus='{traApprClass.IsSp}',ApprovalDate='{DateTime.Now}' where BillNo ='{traApprClass.BillNo}' and ApprovalID='{userXqClass.jobnumber}' and BillClassId='{traApprClass.BillClassId}' and NodeNumber ='{int.Parse(nodeNumber) + 1}'"; da.ExecSql(Sql); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } //更新单据消息id与返回内容 Sql = "update EXPETRAV set IsSp='" + traApprClass.IsSp + "',isAuditing = '1' where billno='" + traApprClass.BillNo + "'"; if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n操作EXPETRAV表" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } //给当前节点以前的人及申请人发送通知,通知已驳回,并改变出差申请表中的状态 sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; logComments = da.GetDataTable(sql); //"【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; for (int i = 0; i < logComments.Rows.Count; i++) { if (i > 0) { logcoments.Append(","); //piddept.Append(","); } sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{logComments.Rows[i]["ApprovalID"].ToString()}'"; //piddept.Append(da.GetValue(sql).ToString()); logcoments.Append(logComments.Rows[i]["ApprovalName"].ToString() + ":" + logComments.Rows[i]["ApprovalComments"].ToString()); } urlcsjson = ddUrl + $"/clfui/shenpi/index.html?billno={traApprClass.BillNo}&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"金额: " + dt.Rows[0]["TotalAmount"].ToString() + "¥ 调休: " + dt.Rows[0]["OffDay"].ToString() + "天\r\n申请人: " + traApprClass.OperatorName + "【差旅费】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请审批日志", "\r\n发送通知调用钉钉api入参:" + CsJson + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的差旅费报销消息通知失败(DD6004)\",\"errcode\":1}"); return; } sql = $"update EXPETRAV set HangState = '0',HangDDIDs = '' where billno = '{traApprClass.BillNo}'"; da.ExecSql(sql); if (IsLocalHost == "0") { result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); } else { result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); ToolsClass.TxtLog("差旅费申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); } return; } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>入参:" + CsJson + "\r\n"); } CCSQ ccsqClass = new CCSQ(); ccsqClass = (CCSQ)JsonConvert.DeserializeObject(CsJson, typeof(CCSQ)); //ccsqClass.Notes = Regex.Replace(ccsqClass.Notes, @"[\n\r]", "").Replace("\\", ""); //ccsqClass.TravelReason = Regex.Replace(ccsqClass.TravelReason, @"[\n\r]", "").Replace("//", ""); if (ccsqClass.Detail.Length <= 0) { context.Response.Write("{\"errmsg\":\"行程不允许为空,请添加行程(DD6001)\",\"errcode\":1}"); return; } try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + ccsqClass.DDOperatorId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取申请人详细信息报错(DD6003)\",\"errcode\":1}"); return; } operatorName = userXqClass.name; #endregion #region 获取用户guid Sql = "select top 1 guid from Employee where employeecode='" + userXqClass.jobnumber + "'"; obj = da.GetValue(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } operatorGuid = obj.ToString(); #endregion #region 获取申请流水号 Sql = "select dbo.GetBillNo('DDTrvelReq','" + userXqClass.jobnumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = "CL" + userXqClass.jobnumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #endregion #region 保存行程信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into TravelReq(BillNo,TravelReason,Notes,DDOperatorId,OperatorGuid,BillDate,SelAuditingGuid,CopyPerson,OperatorName,SelAuditingName,CopyPersonName,AppendixUrl,PictureUrl) Values('").Append(billno).Append("','") .Append(ccsqClass.TravelReason).Append("','") .Append(ccsqClass.Notes).Append("','") .Append(ccsqClass.DDOperatorId).Append("','") .Append(operatorGuid).Append("','") //内部数据库用户GUID .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append(ccsqClass.SelAuditingGuid).Append("','") .Append(ccsqClass.CopyPerson).Append("','") .Append(operatorName).Append("','") .Append(ccsqClass.SelAuditingName).Append("','") .Append(ccsqClass.CopyPersonName).Append("','") .Append(ccsqClass.AppendixUrl).Append("','") .Append(ccsqClass.PictureUrl).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>insert:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into TravelReqDetail(BillNo,Guid,TranMode,OtherTranMode,IsReturn,DepaCity,DepaCity1,DepaCity2,DestCity,DestCity1,DestCity2,StartDate,EndDate,Hours,Days,BearOrga,CustCode,CustName,Peers,PeersName) Values('"); for (int i = 0; i < ccsqClass.Detail.Length; i++) { sqlTi.Clear(); sqlTi.Append(sqlTou.ToString()).Append(billno).Append("','") .Append(Guid.NewGuid().ToString()).Append("','") .Append(ccsqClass.Detail[i].TranMode).Append("','") .Append(ccsqClass.Detail[i].OtherTranMode).Append("','") .Append(ccsqClass.Detail[i].IsReturn).Append("','") .Append(ccsqClass.Detail[i].DepaCity).Append("','") .Append(ccsqClass.Detail[i].DepaCity1).Append("','") .Append(ccsqClass.Detail[i].DepaCity2).Append("','") .Append(ccsqClass.Detail[i].DestCity).Append("','") .Append(ccsqClass.Detail[i].DestCity1).Append("','") .Append(ccsqClass.Detail[i].DestCity2).Append("','") .Append(ccsqClass.Detail[i].StartDate).Append(":01','") .Append(ccsqClass.Detail[i].EndDate).Append(":01','") .Append(ccsqClass.Detail[i].Hours).Append("','") .Append(ccsqClass.Detail[i].Days).Append("','") .Append(ccsqClass.Detail[i].BearOrga).Append("','") .Append(ccsqClass.Detail[i].CustCode).Append("','") .Append(ccsqClass.Detail[i].CustName).Append("','") .Append(ccsqClass.Detail[i].Peers).Append("','") .Append(ccsqClass.Detail[i].PeersName).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>insert:" + sqlTi.ToString() + "\r\n"); } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion #region 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + ccsqClass.SelAuditingGuid + "," + ccsqClass.CopyPerson + "," + ccsqClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + ddUrl + "/shenpi/index.html?billno=" + billno + "\",\"picUrl\":\"@\",\"title\":\"" + operatorName + "的【出差】申请\",\"text\":\"出发日期: " + ccsqClass.Detail[0].StartDate.Substring(0, 10) + "\r\n返程日期: " + ccsqClass.Detail[0].EndDate.Substring(0, 10) + "\r\n事由: " + ccsqClass.TravelReason + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion #region 更新单据消息id与返回内容 //Sql = "update TravelReq set task_id='" + xxtzClass.task_id + "',request_id='" + xxtzClass.request_id + "',returnMsg='" + FhJson.ToString() + "' where billno='" + billno + "'"; //obj = da.ExecSql(Sql); //if (obj == null) //{ // if (isWrite == "1") // { // ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>update:" + Sql.ToString() + "\r\n"); // } // context.Response.Write("{\"errmsg\":\"保存消息通知信息出错(DD6005)\",\"errcode\":1}"); // return; //} #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = "请求方式不允许,请使用POST方式" })); return; } try { string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); string MedConfig180AuditingInfo = ToolsClass.GetConfig("MedConfig180AuditingInfo"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = "报文格式错误" })); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); ToolsClass.TxtLog("获取审批流程信息日志", "\r\n入参:" + CsJson + "\r\n"); //json转Hashtable object jgobj = ToolsClass.DeserializeObject(CsJson); Hashtable returnhash = jgobj as Hashtable; if (returnhash == null) { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = "报文格式错误" })); return; } string path = context.Request.Path.Replace("Approval/ProcessInfo.ashx", "getprocessbegin"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + returnhash["Sign"].ToString() + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != returnhash["Sign"].ToString()) { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = "Sign不正确" })); return; } string MedConfig180 = string.Empty; selType = returnhash["TypeId"].ToString(); DDOperatorId = returnhash["DDOperatorId"].ToString(); DDOperatorName = returnhash["DDOperatorName"].ToString(); if (returnhash.ContainsKey("MedConfig180")) { MedConfig180 = returnhash["MedConfig180"].ToString(); } //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; fjsons = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(fjsons, typeof(TokenClass)); access_token = tokenClass.access_token; int errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"" + tokenClass.errmsg + "\",\"errcode\":1}"); return; } #endregion 获取access_token #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + DDOperatorId; fjsons = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(fjsons, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = userXqClass.errmsg })); return; } #endregion 获取用户详情 List <RUPNodeinfo> NodeInfo = new List <RUPNodeinfo>(); string returnProcess = ""; //取用户信息,进入功能时获取审批流程信息 if (selType == "psin") { //如果是高级领导发起审批 if (da.GetDataTable($"select * from flowemployee where orgcode ='00' and isleader='1' and ddid='{DDOperatorId}' and disable ='0'").Rows.Count != 0) { DataTable roleWithEmp = da.GetDataTable("select distinct Type,PersonId,PersonName from RoleWithEmp where status = '1'"); if (roleWithEmp.Rows.Count == 0) { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = "未配置高级领导审批流程,请联系相关人员进行RoleWithEmp中数据配置!" })); return; } DataRow[] dataRows1, dataRows2 = null; //为1 的是集团财务 dataRows1 = roleWithEmp.Select("Type ='1'"); List <RUPNodeinfodetail> NodeInfoDetailsCW = new List <RUPNodeinfodetail>(), NodeInfoDetailsCN = new List <RUPNodeinfodetail>(); List <RUPPerson> Personscaiwu = new List <RUPPerson>(), Personscn = new List <RUPPerson>(); for (int ri = 0; ri < dataRows1.Length; ri++) { Personscaiwu.Add(new RUPPerson { AType = "集团财务", PersonId = dataRows1[ri]["PersonId"].SqlDataBankToString(), PersonName = dataRows1[ri]["PersonName"].SqlDataBankToString() }); } NodeInfoDetailsCW.Add(new RUPNodeinfodetail { GroupType = "集团财务", IsAndOr = "1", IsLeader = "0", Persons = Personscaiwu }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsCW, NodeInfoType = "2" }); //为2的是出纳 dataRows2 = roleWithEmp.Select("Type ='2'"); for (int ci = 0; ci < dataRows2.Length; ci++) { Personscn.Add(new RUPPerson { AType = "出纳", PersonId = dataRows2[ci]["PersonId"].SqlDataBankToString(), PersonName = dataRows2[ci]["PersonName"].SqlDataBankToString() }); } NodeInfoDetailsCN.Add(new RUPNodeinfodetail { GroupType = "出纳", IsAndOr = "1", IsLeader = "0", Persons = Personscn }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsCN, NodeInfoType = "2" }); returnProcess = JsonConvert.SerializeObject(new ReturnUserProcess { NodeInfo = NodeInfo, errcode = "0", errmsg = "" }); if (isWrite == "1") { ToolsClass.TxtLog("获取审批流程信息日志", "\r\n返回高级领导审批流程:" + returnProcess + "\r\n"); } context.Response.Write(returnProcess); return; } if (MedConfig180 == "1") { List <RUPNodeinfodetail> NodeInfoDetailsYB = new List <RUPNodeinfodetail>(); List <RUPPerson> PersonsYB = new List <RUPPerson>(); NodeInfo.Clear(); PersonsYB.Add(new RUPPerson { AType = "指定人", PersonId = MedConfig180AuditingInfo.Split(',')[0], PersonName = MedConfig180AuditingInfo.Split(',')[1] }); NodeInfoDetailsYB.Add(new RUPNodeinfodetail { GroupType = "指定人", IsAndOr = "1", IsLeader = "0", Persons = PersonsYB }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsYB, NodeInfoType = "2" }); returnProcess = JsonConvert.SerializeObject(new ReturnUserProcess { NodeInfo = NodeInfo, errcode = "0", errmsg = "" }); context.Response.Write(returnProcess); return; } string BillClassId = returnhash["BillClassId"].ToString(); string billName = returnhash["BillName"].ToString(); string deptCode = returnhash["DeptCode"].ToString(); sql = $"select nodeid,BilliClassid,BillClassName,NodeNumber,CharacterTypes,ApprovalType,persons,IsAndOr,IsEnd from ApprovalNode where BilliClassid = '{BillClassId}' order by NodeNumber"; //找到相对应的流程信息 DataTable processdt = da.GetDataTable(sql); DataTable deptdt; DataTable roledt; NodeInfo.Clear(); //嗯 开始组json,如果你看到这段代码,劝你别轻举妄动,仔细观察再改,容易出事,修改之前切记切记,三思而后行 List <RUPPerson> PersonsRy, PersonsJs, PersonsCs, PersonsBm1 = new List <RUPPerson>(), PersonsBm2 = new List <RUPPerson>(), PersonsBm3 = new List <RUPPerson>(), PersonsBm4 = new List <RUPPerson>(), PersonsBm5 = new List <RUPPerson>(); List <RUPNodeinfodetail> NodeInfoDetailsRy, NodeInfoDetailsCs, NodeInfoDetailsJs, NodeInfoDetailsBm1 = new List <RUPNodeinfodetail>(), NodeInfoDetailsBm2 = new List <RUPNodeinfodetail>(), NodeInfoDetailsBm3 = new List <RUPNodeinfodetail>(), NodeInfoDetailsBm4 = new List <RUPNodeinfodetail>(), NodeInfoDetailsBm5 = new List <RUPNodeinfodetail>(); PSPPerson pSPPerson = new PSPPerson(); string deptid, deptname; //是否是主管 PSPApprovalType pSPApprovalType = new PSPApprovalType(); for (int i = 0; i < processdt.Rows.Count; i++) { PSPPerson[] Persons = (PSPPerson[])JsonConvert.DeserializeObject(processdt.Rows[i]["Persons"].SqlDataBankToString(), typeof(PSPPerson[])); if (processdt.Rows[i]["CharacterTypes"].SqlDataBankToString() == "2") { pSPApprovalType = null; pSPApprovalType = (PSPApprovalType)JsonConvert.DeserializeObject(processdt.Rows[i]["ApprovalType"].SqlDataBankToString(), typeof(PSPApprovalType)); //按照人员审批 if (pSPApprovalType.Type == "1") { PersonsRy = new List <RUPPerson>(); NodeInfoDetailsRy = new List <RUPNodeinfodetail>(); for (int k = 0; k < Persons.Length; k++) { PersonsRy.Add(new RUPPerson { AType = "指定人", PersonId = Persons[k].PersonId, PersonName = Persons[k].PersonName }); } NodeInfoDetailsRy.Add(new RUPNodeinfodetail { GroupType = "指定人", IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "0", Persons = PersonsRy }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsRy, NodeInfoType = "2" }); } //按照部门审批 if (pSPApprovalType.Type == "2") { //查询当前的人的级别以及部门编号 取isleader最大的为准 sql = $"select a.IsLeader IsLeader, b.guid orgcode from FlowEmployee a join Organization b on a.orgcode = b. guid where a.EmployeeCode = '{userXqClass.jobnumber}' and a.orgcode ='{deptCode}' and a.disable ='0' order by a.IsLeader desc"; DataTable loinfo = da.GetDataTable(sql); if (loinfo.Rows.Count == 0) { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = "未配置审批流程,请联系相关人员进行FlowEmployee表配置!" })); return; } string leaderlevel = loinfo.Rows[0]["IsLeader"].SqlDataBankToString(); string orgcode = loinfo.Rows[0]["orgcode"].SqlDataBankToString(); //直接主管 一级主管 if (pSPApprovalType.Level == "1") { //判断他是否是主管 if (int.Parse(leaderlevel) > 0) { sql = null; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}') and disable ='0' and IsLeader ='1' "; } else { sql = null; // sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select guid from Organization where guid = '{orgcode}') and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 1}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select guid from Organization where guid = '{orgcode}') and disable ='0' and IsLeader ='1'"; } deptdt = da.GetDataTable(sql); if (deptdt.Rows.Count != 0) { for (int k = 0; k < deptdt.Rows.Count; k++) { deptid = deptdt.Rows[k]["EmployeeCode"].SqlDataBankToString(); deptname = deptdt.Rows[k]["EmployeeName"].SqlDataBankToString(); PersonsBm1.Add(new RUPPerson { AType = "直接主管", PersonId = deptid, PersonName = deptname }); } NodeInfoDetailsBm1.Add(new RUPNodeinfodetail { GroupType = "直接主管", IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "1", Persons = PersonsBm1 }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsBm1, NodeInfoType = "2" }); } } //二级主管 if (pSPApprovalType.Level == "2") { //判断他是否是主管 if (int.Parse(leaderlevel) > 0) { //二级主管 sql = null; //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}')) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 2}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}')) and disable ='0' and IsLeader ='1'"; } else //当前人不是主管 { sql = null; //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}')) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 2}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}')) and disable ='0' and IsLeader ='1'"; } deptdt = da.GetDataTable(sql); if (deptdt.Rows.Count != 0) { for (int k = 0; k < deptdt.Rows.Count; k++) { deptid = deptdt.Rows[k]["EmployeeCode"].SqlDataBankToString(); deptname = deptdt.Rows[k]["EmployeeName"].SqlDataBankToString(); PersonsBm2.Add(new RUPPerson { AType = "二级主管", PersonId = deptid, PersonName = deptname }); } NodeInfoDetailsBm2.Add(new RUPNodeinfodetail { GroupType = "二级主管", IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "1", Persons = PersonsBm2 }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsBm2, NodeInfoType = "2" }); } } //三级主管 if (pSPApprovalType.Level == "3") { //判断他是否是主管 if (int.Parse(leaderlevel) > 0) { sql = null; //三级主管 //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}'))) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 3}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}'))) and disable ='0' and IsLeader ='1"; } else { sql = null; //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}'))) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 3}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}'))) and disable ='0' and IsLeader ='1"; } deptdt = da.GetDataTable(sql); if (deptdt.Rows.Count != 0) { for (int k = 0; k < deptdt.Rows.Count; k++) { deptid = deptdt.Rows[k]["EmployeeCode"].SqlDataBankToString(); deptname = deptdt.Rows[k]["EmployeeName"].SqlDataBankToString(); PersonsBm3.Add(new RUPPerson { AType = "三级主管", PersonId = deptid, PersonName = deptname }); } NodeInfoDetailsBm3.Add(new RUPNodeinfodetail { GroupType = "三级主管", IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "1", Persons = PersonsBm3 }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsBm3, NodeInfoType = "2" }); } } //四级主管 if (pSPApprovalType.Level == "4") { //判断他是否是主管 if (int.Parse(leaderlevel) > 0) { sql = null; //四级主管 //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}')))) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 4}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}')))) and disable ='0' and IsLeader ='1'"; } else { sql = null; //员工的四级主管 //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}')))) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 4}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}')))) and disable ='0' and IsLeader ='1'"; } deptdt = da.GetDataTable(sql); if (deptdt.Rows.Count != 0) { for (int k = 0; k < deptdt.Rows.Count; k++) { deptid = deptdt.Rows[k]["EmployeeCode"].SqlDataBankToString(); deptname = deptdt.Rows[k]["EmployeeName"].SqlDataBankToString(); PersonsBm4.Add(new RUPPerson { AType = "四级主管", PersonId = deptid, PersonName = deptname }); } NodeInfoDetailsBm4.Add(new RUPNodeinfodetail { GroupType = "四级主管", IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "1", Persons = PersonsBm4 }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsBm4, NodeInfoType = "2" }); } } //五级主管 if (pSPApprovalType.Level == "5") { //判断他是否是主管 if (int.Parse(leaderlevel) > 0) { sql = null; //五级主管 //sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}'))))) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 5}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = '{orgcode}'))))) and disable ='0' and IsLeader ='1'"; } else { sql = null; //员工的五级主管 // sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}'))))) and disable ='0' and IsLeader ='{int.Parse(leaderlevel) + 5}'"; sql = $"select EmployeeCode, EmployeeName from FlowEmployee where orgcode =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid =(select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid = (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select case when isnull(Guid,'')='00' then '' else ParentGuid end ParentGuid from Organization where guid= (select guid from Organization where guid = '{orgcode}'))))) and disable ='0' and IsLeader ='1'"; } deptdt = da.GetDataTable(sql); if (deptdt.Rows.Count != 0) { for (int k = 0; k < deptdt.Rows.Count; k++) { deptid = deptdt.Rows[k]["EmployeeCode"].SqlDataBankToString(); deptname = deptdt.Rows[k]["EmployeeName"].SqlDataBankToString(); PersonsBm5.Add(new RUPPerson { AType = "五级主管", PersonId = deptid, PersonName = deptname }); } NodeInfoDetailsBm5.Add(new RUPNodeinfodetail { GroupType = "五级主管", IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "1", Persons = PersonsBm5 }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsBm5, NodeInfoType = "2" }); } } } //按角色审批 type 为3 level 为角色id if (pSPApprovalType.Type == "3") { #region //当前操作人的部门deptCode //当前环节的角色组名称是pSPApprovalType.Level sql = ""; sql = $"select distinct a.EmployeeCode EmployeeCode, a.EmployeeName EmployeeName,b.RoleName RoleName,c.roleid from FlowEmployee a join EmpsRoleId c on a.EmployeeCode = c.EmployeeCode join role b on b.roleid = c.roleid where c.RoleId in (select RoleId from RoleWithOrg where orgcode='{deptCode}' and status ='1') and c.Roleid in (select Roleid from Role where RoleGroupId = '{pSPApprovalType.Level}' and status ='1') and a.disable ='0' and c.status ='1' and b.status='1'"; ToolsClass.TxtLog("获取审批流程信息", "\r\n查询相应角色sql:" + sql + "\r\n"); roledt = da.GetDataTable(sql); if (roledt.Rows.Count != 0) { NodeInfoDetailsJs = new List <RUPNodeinfodetail>(); PersonsJs = new List <RUPPerson>(); for (int k = 0; k < roledt.Rows.Count; k++) { deptid = roledt.Rows[k]["EmployeeCode"].SqlDataBankToString(); deptname = roledt.Rows[k]["EmployeeName"].SqlDataBankToString(); PersonsJs.Add(new RUPPerson { AType = roledt.Rows[k]["RoleName"].SqlDataBankToString(), PersonId = deptid, PersonName = deptname }); } NodeInfoDetailsJs.Add(new RUPNodeinfodetail { GroupType = da.GetValue($"select RoleGroupName from RoleGroup where RoleGroupId ='{pSPApprovalType.Level}'").SqlDataBankToString(), IsAndOr = processdt.Rows[i]["IsAndOr"].SqlDataBankToString(), IsLeader = "0", Persons = PersonsJs }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsJs, NodeInfoType = "2" }); } #endregion } } //抄送环节 if (processdt.Rows[i]["CharacterTypes"].SqlDataBankToString() == "3") { NodeInfoDetailsCs = new List <RUPNodeinfodetail>(); PersonsCs = new List <RUPPerson>(); for (int k = 0; k < Persons.Length; k++) { PersonsCs.Add(new RUPPerson { AType = "抄送人", PersonId = Persons[k].PersonId, PersonName = Persons[k].PersonName }); } NodeInfoDetailsCs.Add(new RUPNodeinfodetail { GroupType = "抄送人", IsAndOr = "", IsLeader = "0", Persons = PersonsCs }); NodeInfo.Add(new RUPNodeinfo { NodeInfoDetails = NodeInfoDetailsCs, NodeInfoType = "3" }); } } returnProcess = JsonConvert.SerializeObject(new ReturnUserProcess { NodeInfo = NodeInfo, errcode = "0", errmsg = "" }); ToolsClass.TxtLog("获取审批流程信息日志", "\r\n返回当前操作人审批流程:" + returnProcess + "\r\n"); context.Response.Write(returnProcess); return; } //获取用户当前的部门 else if (selType == "deptin") { sql = $"select a.IsLeader IsLeader, b.guid orgcode,b.Name orgName,b.ParentGuid from FlowEmployee a join Organization b on a.orgcode = b. guid where a.EmployeeCode = '{userXqClass.jobnumber}' and a.disable = '0'"; DataTable loinfo = da.GetDataTable(sql); string orgcode, orgName, ParentGuid; List <Organization> DeptInfo = new List <Organization>(); for (int i = 0; i < loinfo.Rows.Count; i++) { orgcode = loinfo.Rows[i]["orgcode"].SqlDataBankToString(); orgName = loinfo.Rows[i]["orgName"].SqlDataBankToString(); ParentGuid = loinfo.Rows[i]["ParentGuid"].SqlDataBankToString(); DeptInfo.Add(new Organization { OrgCode = orgcode, OrgName = orgName, ParentGuid = ParentGuid }); } string result = JsonConvert.SerializeObject(new ReturnUserOrg { DeptInfo = DeptInfo, errcode = "0", errmsg = "ok" }); ToolsClass.TxtLog("获取用户当前的部门", $"执行的sql:{ sql }\r\n,返回的数据:\r\n{result}"); context.Response.Write(result); return; } } catch (Exception ex) { context.Response.Write(JsonConvert.SerializeObject(new CommonModel { errcode = "1", errmsg = ex.Message })); return; } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); string JsonData = CsJson; //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n发起申请入参:" + CsJson + "\r\n"); } MulCLFBX mulCLFBX = new MulCLFBX(); mulCLFBX = (MulCLFBX)JsonConvert.DeserializeObject(CsJson, typeof(MulCLFBX)); string ddMessageId = string.Empty; string path = context.Request.Path.Replace("Approval/CLFBXSQ.ashx", "clfbxsqmul"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + mulCLFBX.Sign + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != mulCLFBX.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } //格式固定!! string NodeInfo = JsonConvert.SerializeObject(mulCLFBX.NodeInfo).Replace(",{\"AType\":\"\",\"PersonId\":\"select\",\"PersonName\":\"请选择\"}", ""); if (string.IsNullOrEmpty(NodeInfo)) { context.Response.Write("{\"errmsg\":\"审批流程不正确,请检查后重试!\",\"errcode\":1}"); return; } //[{"NodeInfoType":"2","NodeInfoDetails":[{"Persons":[{"PersonId":"10719","PersonName":"孙鸣国"}],"IsAndOr":"1","IsLeader":"1"}]},{"NodeInfoType":"2","NodeInfoDetails":[{"Persons":[{"PersonId":"10071","PersonName":"岳惠"},{"PersonId":"select","PersonName":"点击选择"}],"IsAndOr":"1","IsLeader":"1"}]},{"NodeInfoType":"3","NodeInfoDetails":[{"Persons":[{"PersonId":"10071","PersonName":"岳惠"},{"PersonId":"10602","PersonName":"王燕春"}],"IsAndOr":"","IsLeader":"0"}]}] mulCLFBX.Notes = Regex.Replace(mulCLFBX.Notes, @"[\n\r]", "").Replace("\\", ""); if (mulCLFBX.ExpeTravDetail.Length <= 0) { context.Response.Write("{\"errmsg\":\"费用明细不允许为空,请添加费用明细(DD7001)\",\"errcode\":1}"); return; } try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token string sqr = mulCLFBX.OperatorName; string fqrall = mulCLFBX.DDOperatorId; string jnumber = mulCLFBX.JobNumber; //获取当前单号的发起人和待报销人 if (mulCLFBX.DDOperatorId != mulCLFBX.InsteadOperatorGuid) { sqr = "【代】" + mulCLFBX.InsteadOperatorName; fqrall = fqrall + "," + mulCLFBX.InsteadOperatorGuid; jnumber = da.GetValue($"select top 1 employeecode from flowemployee where ddid = '{mulCLFBX.InsteadOperatorGuid}'").ToString(); } else { mulCLFBX.OperatorGuid = da.GetValue($"select top 1 guid from flowemployee where ddid = '{fqrall}' and orgcode ='{mulCLFBX.DeptCode}'").ToString(); } if (mulCLFBX.IsRe == "1")//是否需要生产新的申请号 { #region 获取申请流水号 Sql = "select dbo.GetBillNo('DDTrvelReq','" + jnumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = "CL" + jnumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } billno = billno + "_B"; #endregion 获取申请流水号 } else { billno = mulCLFBX.BillNo; if (string.IsNullOrEmpty(billno)) { context.Response.Write("{\"errmsg\":\"请您选择正确的出差单号!\",\"errcode\":1}"); return; } } #region 获取用户guid Sql = $"select top 1 a.GUID,b.TotalAmount,b.OffDay from operators a left join (select sum(TotalAmount) TotalAmount, sum(OffDay) OffDay from ExpetravDetail where billno = '[申请号]' group by billno) b on 1 = 1 where a.code = '[工号]'"; Sql = Sql.Replace("[申请号]", mulCLFBX.BillNo).Replace("[工号]", jnumber); obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; operatorGuid = dt.Rows[0]["GUID"].ToString(); #endregion 获取用户guid if (mulCLFBX.NodeInfo.Length == 0) { //自动同意 #region 保存信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into ExpeTrav(BillNo,BillDate,Notes,DeptName,DeptCode,FlowEmployeeGuid,OperatorGuid,JsonData,ProcessNodeInfo,Applpers,DDOperatorId,BearOrga,CostType,NoCountFee,TravelReason,Urls,IsInsteadApply,InsteadOperatorGuid,PictureUrl) values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append(mulCLFBX.Notes).Append("','") .Append(mulCLFBX.DeptName).Append("','") .Append(mulCLFBX.DeptCode).Append("','") .Append(mulCLFBX.OperatorGuid).Append("','") .Append(operatorGuid).Append("','") .Append(JsonData).Append("','") .Append(NodeInfo).Append("','") .Append(jnumber).Append("','") .Append(mulCLFBX.DDOperatorId).Append("','") .Append(mulCLFBX.BearOrga).Append("','") .Append(mulCLFBX.CostType).Append("','") .Append(mulCLFBX.NoCountFee).Append("','") .Append(mulCLFBX.TravelReason).Append("','") .Append(JsonConvert.SerializeObject(mulCLFBX.Urls)).Append("','") .Append(mulCLFBX.IsInsteadApply).Append("','") .Append(mulCLFBX.InsteadOperatorGuid).Append("','") .Append(mulCLFBX.PictureUrl).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into ExpetravDetail(TripNo,BillNo,Guid,DepaDate,RetuDate,DepaCity,DestCity,DepaCity1,DestCity1,CustCode,DetailNo,AlloDay,OffDay,AlloPric,AlloAmount,OtherFee,TranMode,TranCount,TranAmount,GasAmount,HsrAmount,AccoCount,AccoAmount,CityTrafCount,CityTraAmont,TotalAmount) values('"); for (int i = 0; i < mulCLFBX.ExpeTravDetail.Length; i++) { oneSumAmount = 0;//第一行的和 SumMony = SumMony + Double.Parse(mulCLFBX.ExpeTravDetail[i].TotalAmount); sqlTiPro.Clear(); detailNo = detailNo + 1; TripNo = 1; sqlTiPro.Append(sqlTou.ToString()).Append(i + 1).Append("','") .Append(billno).Append("',newid(),'") .Append(mulCLFBX.ExpeTravDetail[i].DepaDate).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].RetuDate).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DepaCity3).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DestCity3).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DepaCity1).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DestCity1).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].CustCode).Append("','"); for (int j = 0; j < mulCLFBX.ExpeTravDetail[i].PList.Length; j++) { if (j == 0) { sqlTi.Clear(); sqlTi.Append(sqlTiPro.ToString()).Append(detailNo) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].AlloDay) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].OffDay) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].AlloPric) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].AlloAmount) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].OtherFee); oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].AlloAmount) + Double.Parse(mulCLFBX.ExpeTravDetail[i].OtherFee); } if (TripNo == 1) { sqlTi.Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0"); oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].PList[j].Amount); detailNo = detailNo + 1; TripNo = TripNo + 1; } else { sqlTi2.Clear(); sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0','0','0','0','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount) .Append("')"); sqlList.Add(sqlTi2.ToString()); detailNo = detailNo + 1; TripNo = TripNo + 1; ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTi2.ToString() + "\r\n"); } #region 原有逻辑 //if (mulCLFBX.ExpeTravDetail[i].PList[j].FType == "火车票" || mulCLFBX.ExpeTravDetail[i].PList[j].FType == "飞机票" || mulCLFBX.ExpeTravDetail[i].PList[j].FType == "汽车票" || mulCLFBX.ExpeTravDetail[i].PList[j].FType == "轮船票") //{ // if (TripNo == 1) // { // sqlTi.Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Amount) // .Append("','0','0"); // oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].PList[j].Amount); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // } // else // { // sqlTi2.Clear(); // sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Amount) // .Append("','0','0','0','0','0','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount) // .Append("')"); // sqlList.Add(sqlTi2.ToString()); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTi2.ToString() + "\r\n"); // } //} //else if (mulCLFBX.ExpeTravDetail[i].PList[j].FType == "自驾") //{ // if (TripNo == 1) // { // sqlTi.Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) // .Append("','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].GasAmount) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].HsrAmount); // oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // } // else // { // sqlTi2.Clear(); // sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) // .Append("','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].GasAmount).Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].HsrAmount).Append("','0','0','0','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount) // .Append("')"); // sqlList.Add(sqlTi2.ToString()); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTi2.ToString() + "\r\n"); // } //} //else if (mulCLFBX.ExpeTravDetail[i].PList[j].FType == "住宿票") //{ // AccoCount = mulCLFBX.ExpeTravDetail[i].PList[j].Count; // AccoAmount = mulCLFBX.ExpeTravDetail[i].PList[j].Amount; // if (TripNo == 1) // { // oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].PList[j].Amount); // sqlTi.Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) // //.Append("','").Append("0") // //.Append("','").Append("0") // .Append("','").Append(AccoCount) // .Append("','").Append(AccoAmount) // .Append("','0','0"); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // } // else // { // sqlTi2.Clear(); // sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) // //.Append("','").Append("0") // //.Append("','").Append("0") // .Append("','").Append(AccoCount) // .Append("','").Append(AccoAmount) // .Append("','0','0','") // .Append(AccoCount) // .Append("','") // .Append(AccoAmount) // .Append("','0','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount) // .Append("')"); // sqlList.Add(sqlTi2.ToString()); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // ToolsClass.TxtLog("差旅费申请日志", "\r\n住宿票:" + sqlTi2.ToString() + "\r\n"); // } //} //else if (mulCLFBX.ExpeTravDetail[i].PList[j].FType == "市内交通票") //{ // CityTrafCount = mulCLFBX.ExpeTravDetail[i].PList[j].Count; // CityTraAmount = mulCLFBX.ExpeTravDetail[i].PList[j].Amount; // if (TripNo == 1) // { // oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].PList[j].Amount); // sqlTi.Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) // //.Append("','").Append("0") // //.Append("','").Append("0") // .Append("','").Append(CityTrafCount) // .Append("','").Append(CityTraAmount) // .Append("','0','0"); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // } // else // { // sqlTi2.Clear(); // sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) // //.Append("','").Append("0") // //.Append("','").Append("0") // .Append("','").Append(CityTrafCount) // .Append("','").Append(CityTraAmount) // .Append("','0','0','0','0','") // .Append(CityTrafCount) // .Append("','") // .Append(CityTraAmount) // .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount) // .Append("')"); // sqlList.Add(sqlTi2.ToString()); // detailNo = detailNo + 1; // TripNo = TripNo + 1; // ToolsClass.TxtLog("差旅费申请日志", "\r\n市内交通票:" + sqlTi2.ToString() + "\r\n"); // } //} #endregion 原有逻辑 } //sqlTi.Append("','").Append(AccoCount) // .Append("','").Append(AccoAmount) // .Append("','").Append(CityTrafCount) // .Append("','").Append(CityTraAmount) // .Append("','").Append(oneSumAmount).Append("')"); sqlTi.Append("','").Append("0") .Append("','").Append("0") .Append("','").Append("0") .Append("','").Append("0") .Append("','").Append(oneSumAmount).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTi.ToString() + "\r\n"); } } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存信息 #region 调用提交存储过程 keyValuePairs = CommonHelper.sqlPro(billno, "100520005005", operatorGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("差旅费申请日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); aList.Clear(); Sql = "delete from ExpeTrav where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from ExpetravDetail where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from CUSTIMPLLOG where SourceBill='" + billno + "'"; aList.Add(Sql); obj = da.ExecSql(aList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); return; } #endregion 调用提交存储过程 Sql = "update EXPETRAV set IsSp='1' where billno where billno='" + billno + "'"; if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n操作EXPETRAV表:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); urlcsjson = ddUrl + $"/clfui/shenpi/index.html?billno={billno}&BillClassId={mulCLFBX.BillClassId}&showmenu=false"; urlcsjson = System.Web.HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + sqr + "的【差旅费】报销申请\",\"text\":\"金额: " + SumMony + " ¥\r\n行程: " + mulCLFBX.ExpeTravDetail[0].DepaCity1 + " - " + mulCLFBX.ExpeTravDetail[0].DestCity1 + "\r\n申请日期: " + System.DateTime.Now.ToString("yyyy-MM-dd") + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); var xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); ddMessageId = xxtzClass2.task_id.ToString(); context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } //获取第一级流程的人员信息 NodeInfoDetailPerson[] NodeInfodetailPeople = mulCLFBX.NodeInfo[0].NodeInfoDetails[0].Persons; //从入参中得到审批人及抄送人的信息 //指定人员的id列表 StringBuilder piddept = new StringBuilder(); string sql = ""; for (int i = 0; i < NodeInfodetailPeople.Length; i++) { if (i > 0) { piddept.Append(","); } //判断传空 if (NodeInfodetailPeople[i].PersonId != "select" && NodeInfodetailPeople[i].PersonId != "") { sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'"; piddept.Append(da.GetValue(sql).ToString()); } } #region 保存信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into ExpeTrav(BillNo,BillDate,Notes,DeptName,DeptCode,OperatorGuid,FlowEmployeeGuid,JsonData,ProcessNodeInfo,Applpers,DDOperatorId,BearOrga,CostType,NoCountFee,TravelReason,Urls,IsInsteadApply,InsteadOperatorGuid,PictureUrl) values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append(mulCLFBX.Notes).Append("','") .Append(mulCLFBX.DeptName).Append("','") .Append(mulCLFBX.DeptCode).Append("','") .Append(operatorGuid).Append("','") .Append(mulCLFBX.OperatorGuid).Append("','") .Append(JsonData).Append("','") .Append(NodeInfo).Append("','") .Append(jnumber).Append("','") .Append(mulCLFBX.DDOperatorId).Append("','") .Append(mulCLFBX.BearOrga).Append("','") .Append(mulCLFBX.CostType).Append("','") .Append(mulCLFBX.NoCountFee).Append("','") .Append(mulCLFBX.TravelReason).Append("','") .Append(JsonConvert.SerializeObject(mulCLFBX.Urls)).Append("','") .Append(mulCLFBX.IsInsteadApply).Append("','") .Append(mulCLFBX.InsteadOperatorGuid).Append("','") .Append(mulCLFBX.PictureUrl).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into ExpetravDetail(TripNo,BillNo,Guid,DepaDate,RetuDate,DepaCity,DestCity,DepaCity1,DestCity1,CustCode,DetailNo,AlloDay,OffDay,AlloPric,AlloAmount,OtherFee,TranMode,TranCount,TranAmount,GasAmount,HsrAmount,AccoCount,AccoAmount,CityTrafCount,CityTraAmont,TotalAmount) values('"); for (int i = 0; i < mulCLFBX.ExpeTravDetail.Length; i++) { oneSumAmount = 0;//第一行的和 SumMony = SumMony + Double.Parse(mulCLFBX.ExpeTravDetail[i].TotalAmount); sqlTiPro.Clear(); detailNo = detailNo + 1; TripNo = 1; sqlTiPro.Append(sqlTou.ToString()).Append(i + 1).Append("','") .Append(billno).Append("',newid(),'") .Append(mulCLFBX.ExpeTravDetail[i].DepaDate).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].RetuDate).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DepaCity3).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DestCity3).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DepaCity1).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].DestCity1).Append("','") .Append(mulCLFBX.ExpeTravDetail[i].CustCode).Append("','"); for (int j = 0; j < mulCLFBX.ExpeTravDetail[i].PList.Length; j++) { if (j == 0) { sqlTi.Clear(); sqlTi.Append(sqlTiPro.ToString()).Append(detailNo) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].AlloDay) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].OffDay) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].AlloPric) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].AlloAmount) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].OtherFee); oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].AlloAmount) + Double.Parse(mulCLFBX.ExpeTravDetail[i].OtherFee); } if (TripNo == 1) { sqlTi.Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0"); oneSumAmount = oneSumAmount + Double.Parse(mulCLFBX.ExpeTravDetail[i].PList[j].Amount); detailNo = detailNo + 1; TripNo = TripNo + 1; } else { sqlTi2.Clear(); sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0','0','0','0','0','").Append(mulCLFBX.ExpeTravDetail[i].PList[j].SumAmount) .Append("')"); sqlList.Add(sqlTi2.ToString()); detailNo = detailNo + 1; TripNo = TripNo + 1; ToolsClass.TxtLog("差旅费申请日志", "\r\n明细表:" + sqlTi2.ToString() + "\r\n"); } } sqlTi.Append("','").Append("0") .Append("','").Append("0") .Append("','").Append("0") .Append("','").Append("0") .Append("','").Append(oneSumAmount).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ExpeTravReq表:" + sqlTi.ToString() + "\r\n"); } } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存信息 #region 调用提交存储过程 keyValuePairs = CommonHelper.sqlPro(billno, "100520005005", operatorGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("差旅费申请日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); aList.Clear(); Sql = "delete from ExpeTrav where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from ExpetravDetail where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from CUSTIMPLLOG where SourceBill='" + billno + "'"; aList.Add(Sql); obj = da.ExecSql(aList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); return; } #endregion 调用提交存储过程 #region 差旅费报销 申请 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; urlcsjson = ddUrl + $"/clfui/shenpi/index.html?billno={billno}&BillClassId={mulCLFBX.BillClassId}&showmenu=false"; urlcsjson = System.Web.HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + sqr + "的【差旅费】报销申请\",\"text\":\"金额: " + SumMony + " ¥\r\n行程: " + mulCLFBX.ExpeTravDetail[0].DepaCity1 + " - " + mulCLFBX.ExpeTravDetail[0].DestCity1 + "\r\n申请日期: " + System.DateTime.Now.ToString("yyyy-MM-dd") + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; ddMessageId = xxtzClass.task_id.ToString(); if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的差旅费报销申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion 差旅费报销 申请 发送工作通知消息 //保存流程信息到comments表 sqlList.Clear(); for (int i = 0; i < NodeInfodetailPeople.Length; i++) { sqlTou.Clear(); if (NodeInfodetailPeople[i].PersonId != "select") { sqlTou.Append("insert into ApprovalComments(CommentsId,BillClassId,BillNo,ApprovalID,ApprovalName,ApprovalComments,ApprovalStatus,DDMessageId,AType,ApprovalDate,IsAndOr,IsLeader,PersonType,NodeNumber) values('").Append(Guid.NewGuid().ToString()).Append("','") .Append(mulCLFBX.BillClassId).Append("','") .Append(billno).Append("','") .Append(NodeInfodetailPeople[i].PersonId).Append("','") .Append(NodeInfodetailPeople[i].PersonName).Append("','")//内部数据库用户GUID .Append("").Append("','") .Append("0").Append("','") .Append(ddMessageId).Append("','") .Append(NodeInfodetailPeople[i].AType).Append("','") .Append(DateTime.Now).Append("','") .Append(mulCLFBX.NodeInfo[0].NodeInfoDetails[0].IsAndOr).Append("','") .Append(mulCLFBX.NodeInfo[0].NodeInfoDetails[0].IsLeader).Append("','") .Append(mulCLFBX.NodeInfo[0].NodeInfoType).Append("','") .Append("2").Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("差旅费申请日志", "\r\n操作ApprovalComments表:" + sqlTou.ToString() + "\r\n"); } } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存差旅费报销申请节点信息出错(DD6002)\",\"errcode\":1}"); return; } //string path = context.Request.Path.Replace("Approval/CLFBXSQ.ashx", "clfbxsqmul"); path = context.Request.Path.Replace("Approval/CLFBXSQ.ashx", "clfbxspmul"); //验证请求sign sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); TaskFactory taskFactory = new TaskFactory(); //如果下个是抄送人 if (mulCLFBX.NodeInfo[0].NodeInfoType == "3") { //根据数据开启多个线程调用审批接口 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "clfbxspmul"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = billno, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsSp = "3", DDOperatorId = mulCLFBX.InsteadOperatorGuid, OperatorName = mulCLFBX.InsteadOperatorName, BillClassId = mulCLFBX.BillClassId, Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } }); } if (mulCLFBX.NodeInfo[0].NodeInfoType == "2") { DataRow[] dataRows = null; sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{billno}' and BillClassId='{mulCLFBX.BillClassId}' and ApprovalStatus ='1'"; DataTable logComments = da.GetDataTable(sql); //如果下个环节中的人在之前已同意,自动调用此接口同意完成审批 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { dataRows = logComments.Select("ApprovalID ='" + NodeInfodetailPeople[i].PersonId + "'"); //如果之前已经同意或者是发起人 if (dataRows.Length != 0 || da.GetValue($"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'").ToString() == mulCLFBX.InsteadOperatorGuid) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "clfbxspmul"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = billno, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsSp = "1", DDOperatorId = mulCLFBX.InsteadOperatorGuid, OperatorName = mulCLFBX.InsteadOperatorName, BillClassId = mulCLFBX.BillClassId, AuditingIdea = "同意", Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } } }); } //如果是撤回重新提交的,删除之前的单子 if (!string.IsNullOrEmpty(mulCLFBX.OldBillNo)) { da.ExecSql($"delete ExpetravDetail where billno = '{mulCLFBX.OldBillNo}'"); da.ExecSql($"delete ExpeTrav where billno = '{mulCLFBX.OldBillNo}'"); da.ExecSql($"delete approvalcomments where billno = '{mulCLFBX.OldBillNo}'"); da.Dispose(); ToolsClass.TxtLog("其他费用报销申请日志", "\r\n删除旧单据:" + $"delete ExpetravDetail where billno = '{mulCLFBX.OldBillNo}'" + $"delete ExpeTrav where billno = '{mulCLFBX.OldBillNo}'" + "\r\n"); } context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "\" " + ex.Message + ",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApproval traApprClass = new TravelApproval(); traApprClass = (TravelApproval)JsonConvert.DeserializeObject(CsJson, typeof(TravelApproval)); try { if (traApprClass.IsAuditing == "1") { audiIdea = "同意"; } else if (traApprClass.IsAuditing == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } audiName = userXqClass.name; #endregion #region 获取用户guid Sql = "select top 1 a.guid,b.StartDate,b.EndDate from FlowEmployee a left join (select convert(varchar(20), min(b.StartDate), 23) StartDate,convert(varchar(20), max(EndDate), 23) EndDate from TravelReq a left join TravelReqDetail b on a.billno = b.billno where a.billno = '" + traApprClass.BillNo + "' group by a.billno) b on 1 = 1 where a.employeecode = '" + userXqClass.jobnumber + "'"; obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD9002)\",\"errcode\":1}"); return; } dt = obj as DataTable; if (dt.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"申请信息不存在(DD9003)\",\"errcode\":1}"); return; } AuditingGuid = dt.Rows[0]["guid"].ToString(); #endregion #region 发送工作通知消息 CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.DDAuditingId + "," + traApprClass.CopyPerson + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + ddUrl + "/shenpi/index.html?billno=" + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n申请人: " + traApprClass.OperatorName + "【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); } XXTZ xxtzClass2 = new XXTZ(); xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion #region 发送普通会话消息 //if (traApprClass.Cid != "" && traApprClass.Cid != null) //{ // CsJson = "{\"cid\":\"" + traApprClass.Cid + "\",\"sender\":\"" + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"http://oa.romens.cn:8090/shenpi/index.html?billno=" + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "\",\"text\":\"" + audiName + audiIdea + "了审批\"}}}"; // url = "https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + access_token; // FhJson = ToolsClass.ApiFun("POST", url, CsJson); // if (isWrite == "1") // { // ToolsClass.TxtLog("DDLog", "\r\nProInfo=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); // } // XXTZ xxtzClass = new XXTZ(); // xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); // errcode = xxtzClass.errcode; // if (errcode != 0) // { // context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); // return; // } //} #endregion #region 更新审批信息 //更新单据消息id与返回内容 Sql = "update TravelReq set isauditing='" + traApprClass.IsAuditing + "',auditingdate=getdate(),auditingidea='" + traApprClass.AuditingIdea + "',DDAuditingId='" + traApprClass.DDAuditingId + "',auditingguid='" + AuditingGuid + "',auditingname='" + audiName + "' where billno='" + traApprClass.BillNo + "'"; if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>update:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); if (obj == null) { if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>update:" + Sql.ToString() + "\r\n"); } context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfAudi=>入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApproval traApprClass = new TravelApproval(); traApprClass = (TravelApproval)JsonConvert.DeserializeObject(CsJson, typeof(TravelApproval)); try { if (traApprClass.IsSp == "1") { audiIdea = "同意"; } else if (traApprClass.IsSp == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } if (traApprClass.FeeType == "01") { //市内交通费 billTypeNo = "100520005015"; ProName = "EXPEAUDITING"; typeName = "交通费"; typeUrl = ddUrl + "/jtfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "02") { //通讯费 billTypeNo = "100520005020"; ProName = "EXPEAUDITING"; typeName = "通讯费"; typeUrl = ddUrl + "/txfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "03") { //车辆费 billTypeNo = "100520005025"; ProName = "EXPEAUDITING"; typeName = "车辆费"; typeUrl = ddUrl + "/clui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "04") { //房租费 billTypeNo = "100520005030"; ProName = "EXPEAUDITING"; typeName = "房租费"; typeUrl = ddUrl + "/fzfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "05") { //水费 billTypeNo = "100520005035"; ProName = "EXPEAUDITING"; typeName = "水费"; typeUrl = ddUrl + "/sfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "06") { //电费 billTypeNo = "100520005040"; ProName = "EXPEAUDITING"; typeName = "电费"; typeUrl = ddUrl + "/dfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "00") { //招待费 billTypeNo = "100520005010"; ProName = "EXPEAUDITING"; typeName = "招待费"; typeUrl = ddUrl + "/zdfui/shenpi/index.html?billno="; } else { context.Response.Write("{\"errmsg\":\"提交的报销类型不存在(DD9001)\",\"errcode\":1}"); return; } #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } audiName = userXqClass.name; #endregion #region 获取用户guid if (traApprClass.FeeType == "00") { Sql = "select top 1 a.Guid,b.BillCount,b.FeeAmount from Employee a left join (select BillCount,FeeAmount from EXPEENTEMENT where billno = '[申请号]') b on 1 = 1 where a.employeecode = '[工号]'"; } else { Sql = "select top 1 a.Guid,b.BillCount,b.FeeAmount from Employee a left join (select BillCount,FeeAmount from EXPEOTHER where billno = '[申请号]') b on 1 = 1 where a.employeecode = '[工号]'"; } Sql = Sql.Replace("[申请号]", traApprClass.BillNo).Replace("[工号]", userXqClass.jobnumber); obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; AuditingGuid = dt.Rows[0]["Guid"].ToString(); #endregion #region 更新审批信息 if (traApprClass.FeeType == "00") { //更新单据消息id与返回内容 Sql = "update EXPEENTEMENT set IsSp='" + traApprClass.IsSp + "',auditingidea='" + traApprClass.AuditingIdea + "',DDAuditingId='" + traApprClass.DDAuditingId + "',auditingguid='" + AuditingGuid + "' where billno='" + traApprClass.BillNo + "'"; } else { //更新单据消息id与返回内容 Sql = "update EXPEOTHER set IsSp='" + traApprClass.IsSp + "',auditingidea='" + traApprClass.AuditingIdea + "',DDAuditingId='" + traApprClass.DDAuditingId + "',auditingguid='" + AuditingGuid + "' where billno='" + traApprClass.BillNo + "'"; } if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfAudi=>update:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #endregion #region 调用审核存储过程 if (traApprClass.IsSp == "1") { billno = traApprClass.BillNo; if (!sqlPro()) { if (traApprClass.FeeType == "00") { Sql = "update EXPEENTEMENT set IsSp='0',auditingidea=null,DDAuditingId=null,auditingguid=null where billno='" + traApprClass.BillNo + "'"; } else { Sql = "update EXPEOTHER set IsSp='0',auditingidea=null,DDAuditingId=null,auditingguid=null where billno='" + traApprClass.BillNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批状态出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + ProResult + "(DD9003)\",\"errcode\":1}"); return; } } #endregion #region 发送工作通知消息 CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.DDAuditingId + "," + traApprClass.CopyPerson + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + "" + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"金额: " + dt.Rows[0]["FeeAmount"].ToString() + "¥ 发票: " + dt.Rows[0]["BillCount"].ToString() + "张\r\n申请人: " + traApprClass.OperatorName + "【" + typeName + "】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfAudi=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); } XXTZ xxtzClass2 = new XXTZ(); xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
private string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); SqlHelper = new BankDbHelper.SqlHelper("SqlServer", connectionString); string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } GetMulParams getMulParams = new GetMulParams(); string result = string.Empty; if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n申请审批入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApprovalMul traApprClass = new TravelApprovalMul(); traApprClass = (TravelApprovalMul)JsonConvert.DeserializeObject(CsJson, typeof(TravelApprovalMul)); string path = context.Request.Path.Replace("Approval/TSPM.ashx", "tasp"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + traApprClass.Sign + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != traApprClass.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } audiName = userXqClass.name; #endregion 获取用户详情 #region 获取用户guid Sql = "select top 1 a.guid,b.StartDate,b.EndDate from FlowEmployee a left join (select convert(varchar(20), min(b.StartDate), 23) StartDate,convert(varchar(20), max(EndDate), 23) EndDate from TravelReq a left join TravelReqDetail b on a.billno = b.billno where a.billno = '" + traApprClass.BillNo + "' group by a.billno) b on 1 = 1 where a.employeecode = '" + userXqClass.jobnumber + "'"; obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD9002)\",\"errcode\":1}"); return; } dt = obj as DataTable; if (dt.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"申请信息不存在(DD9003)\",\"errcode\":1}"); return; } AuditingGuid = dt.Rows[0]["guid"].ToString(); #endregion 获取用户guid //判断当前是流程节点中的哪个流程 Sql = $"select count( DISTINCT NodeNumber) NodeNumber from ApprovalComments where BillNo ='{traApprClass.BillNo}'"; //得到当前流程节点的数量 string nodeNumber = da.GetValue(Sql).ToString(); //得到当前流程信息 NodeInfo[] NodeInfo = (NodeInfo[])JsonConvert.DeserializeObject(da.GetValue($"select ProcessNodeInfo from TravelReq where BillNo='{traApprClass.BillNo}'").ToString(), typeof(NodeInfo[])); XXTZ xxtzClass2 = new XXTZ(); StringBuilder piddept = new StringBuilder(); string sql = ""; DataTable logComments = new DataTable(); StringBuilder logcoments = new StringBuilder(); if (traApprClass.IsAuditing == "1") { audiIdea = "同意"; } else if (traApprClass.IsAuditing == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } //如果审批人意见为同意 if (audiIdea == "同意" || audiIdea == "抄送") { //将意见及日期保存到ApprovalComments表,并改变状态 Sql = ""; Sql = $"update ApprovalComments set ApprovalComments='{traApprClass.AuditingIdea}',Urls='{JsonConvert.SerializeObject(traApprClass.Urls)}',ApprovalStatus='{traApprClass.IsAuditing}',ApprovalDate='{DateTime.Now}' where BillNo ='{traApprClass.BillNo}' and ApprovalID='{userXqClass.jobnumber}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; da.ExecSql(Sql); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } bool processIsEnd = false; //判断当前节点是领导还是非领导 Sql = ""; // 1 2 3 null Sql = $"select distinct IsLeader IsLeader, IsAndOr IsAndOr from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; DataTable IsLeader = da.GetDataTable(Sql); if (IsLeader.Rows[0]["IsLeader"].ToString() == "1") { //领导为一次审批或者会签 if (IsLeader.Rows[0]["IsAndOr"].ToString() == "1" || IsLeader.Rows[0]["IsAndOr"].ToString() == "2") { Sql = ""; // 1 2 3 null Sql = $"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'"; //当前节点未完成 if (da.GetValue(Sql).ToString() != "0") { processIsEnd = false; result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } else { processIsEnd = true; } } //领导为或签 else if (IsLeader.Rows[0]["IsAndOr"].ToString() == "3") { processIsEnd = true; Sql = ""; // 1 2 3 null Sql = $"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'"; //当前节点未完成 if (da.GetValue(Sql).ToString() != "0") { processIsEnd = false; result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } else { Sql = ""; Sql = $"update ApprovalComments set ApprovalStatus='1',ApprovalComments='工号为{userXqClass.jobnumber}的审批人已签',ApprovalDate='{DateTime.Now}' where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}' and ApprovalStatus='0'"; da.ExecSql(Sql); } if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } } } //如果不是领导 if (IsLeader.Rows[0]["IsLeader"].ToString() != "1") { if (IsLeader.Rows[0]["IsAndOr"].ToString() == "1" || IsLeader.Rows[0]["IsAndOr"].ToString() == "2") { Sql = ""; // 1 2 3 null Sql = $"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'"; //当前节点未完成 if (da.GetValue(Sql).ToString() != "0") { processIsEnd = false; result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } else { processIsEnd = true; } } else if (IsLeader.Rows[0]["IsAndOr"].ToString() == "3") { processIsEnd = true; Sql = ""; // 1 2 3 null Sql = $"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'"; //当前节点未完成 if (da.GetValue(Sql).ToString() != "0") { processIsEnd = false; result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } else { Sql = ""; Sql = $"update ApprovalComments set ApprovalStatus='1',ApprovalComments='工号为{userXqClass.jobnumber}的审批人已签',ApprovalDate='{DateTime.Now}' where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}' and ApprovalStatus='0'"; da.ExecSql(Sql); } if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } } else { processIsEnd = true; } } //可以给下个人发送消息 if (processIsEnd) //如果当前流程节点走完 { //判断当前单号是否已经结束 sql = ""; sql = $"select IsAuditing from TravelReq where BillNo ='{traApprClass.BillNo}'"; if (da.GetValue(sql).ToString() != "0") { result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } //判断是否是根结点,判断数量(去重)是否小于流程的长度 //是否是最后一个流程 // if (int.Parse(nodeNumber) < NodeInfo.Length && da.GetValue($"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'").ToString() != "0") if (int.Parse(nodeNumber) < NodeInfo.Length) { //获取下个节点的人员信息 NodeInfoDetailPerson[] NodeInfodetailPeople = NodeInfo[int.Parse(nodeNumber)].NodeInfoDetails[0].Persons; for (int i = 0; i < NodeInfodetailPeople.Length; i++) { if (i > 0) { piddept.Append(","); } //判断传空 if (NodeInfodetailPeople[i].PersonId != "") { sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'"; piddept.Append(da.GetValue(sql).ToString()); } } //插入相应的信息到comments表中 sqlList.Clear(); for (int i = 0; i < NodeInfodetailPeople.Length; i++) { sqlTou.Clear(); sqlTou.Append("insert into ApprovalComments(CommentsId,BillClassId,BillNo,ApprovalID,ApprovalName,ApprovalComments,ApprovalStatus,AType,ApprovalDate,IsAndOr,IsLeader,PersonType,NodeNumber) values('") .Append(Guid.NewGuid().ToString()).Append("','") .Append(traApprClass.BillClassId).Append("','") .Append(traApprClass.BillNo).Append("','") .Append(NodeInfodetailPeople[i].PersonId).Append("','") .Append(NodeInfodetailPeople[i].PersonName).Append("','")//内部数据库用户GUID .Append("").Append("','") .Append("0").Append("','") .Append(NodeInfodetailPeople[i].AType).Append("','") .Append(DateTime.Now).Append("','") .Append(NodeInfo[int.Parse(nodeNumber)].NodeInfoDetails[0].IsAndOr).Append("','") .Append(NodeInfo[int.Parse(nodeNumber)].NodeInfoDetails[0].IsLeader).Append("','") .Append(NodeInfo[int.Parse(nodeNumber)].NodeInfoType).Append("','") .Append(int.Parse(nodeNumber) + 2).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + sqlTou.ToString() + "\r\n"); } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请节点信息出错(DD6002)\",\"errcode\":1}"); return; } //给申请人发送审批意见 给下个节点的人员发送目前为止的审批状态及意见,给之前的人也发 //获取现在的审批意见 sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; logComments = da.GetDataTable(sql); //"【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; for (int i = 0; i < logComments.Rows.Count; i++) { if (i > 0) { logcoments.Append(","); } //piddept.Append(","); sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{logComments.Rows[i]["ApprovalID"].ToString()}'"; //piddept.Append(da.GetValue(sql).ToString()); logcoments.Append(logComments.Rows[i]["ApprovalName"].ToString() + ":" + logComments.Rows[i]["ApprovalComments"].ToString()); } urlcsjson = ddUrl + $"/shenpi/index.html?billno={traApprClass.BillNo}&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n申请人: " + traApprClass.OperatorName + "【出差】\r\n审批意见: " + logcoments.ToString() + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n发送通知出入参:" + CsJson + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n多级流程出差审批发送通知失败" + "钉钉id不正确!"); context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } TaskFactory taskFactory = new TaskFactory(); //如果下个是抄送人 if (NodeInfo[int.Parse(nodeNumber)].NodeInfoType == "3") { //根据数据开启多个线程调用审批接口 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "tasp"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = traApprClass.BillNo, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsAuditing = "3", DDOperatorId = traApprClass.DDOperatorId, OperatorName = traApprClass.OperatorName, BillClassId = traApprClass.BillClassId , Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } }); } if (NodeInfo[int.Parse(nodeNumber)].NodeInfoType == "2") { DataRow[] dataRows = null; sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}' and ApprovalStatus ='1'"; logComments = da.GetDataTable(sql); //如果下个环节中的人在之前已同意,自动调用此接口同意完成审批 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { dataRows = logComments.Select("ApprovalID ='" + NodeInfodetailPeople[i].PersonId + "'"); if (dataRows.Length != 0 || da.GetValue($"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'").ToString() == traApprClass.DDOperatorId) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "tasp"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = traApprClass.BillNo, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsAuditing = "1", DDOperatorId = traApprClass.DDOperatorId, OperatorName = traApprClass.OperatorName, BillClassId = traApprClass.BillClassId, AuditingIdea = "同意", Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } } }); } } //如果是最后一级 //给申请人发送审批意见 给之前的人发 //获取现在的审批意见 else { //更新单据消息id与返回内容 Sql = "update TravelReq set isauditing='1',auditingdate=getdate() where billno='" + traApprClass.BillNo + "'"; if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作TravelReq表:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; logComments = da.GetDataTable(sql); //"【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; for (int i = 0; i < logComments.Rows.Count; i++) { if (i > 0) { logcoments.Append(","); //piddept.Append(","); } sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{logComments.Rows[i]["ApprovalID"].ToString()}'"; //piddept.Append(da.GetValue(sql).ToString()); logcoments.Append(logComments.Rows[i]["ApprovalName"].ToString() + ":" + logComments.Rows[i]["ApprovalComments"].ToString()); } urlcsjson = ddUrl + $"/shenpi/index.html?billno={traApprClass.BillNo}&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n申请人: " + traApprClass.OperatorName + "【出差】\r\n审批意见: " + logcoments.ToString() + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n发送通知出入参=>CsJson:" + CsJson + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } } } result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } //如果是已驳回,给操作人发送通知,将意见及日期保存到ApprovalComments表,并改变状态,,改变出差申请表中的状态,改为2,代表已驳回 if (audiIdea == "驳回") { //将意见及日期保存到ApprovalComments表,并改变状态 Sql = ""; Sql = $"update ApprovalComments set ApprovalComments='{traApprClass.AuditingIdea}',Urls='{JsonConvert.SerializeObject(traApprClass.Urls)}',ApprovalStatus='{traApprClass.IsAuditing}',ApprovalDate='{DateTime.Now}' where BillNo ='{traApprClass.BillNo}' and ApprovalID='{userXqClass.jobnumber}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; da.ExecSql(Sql); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } bool processIsEnd = false; //判断当前节点是领导还是非领导 Sql = ""; // 1 2 3 null Sql = $"select distinct IsLeader IsLeader, IsAndOr IsAndOr from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and BillClassId='{traApprClass.BillClassId}'"; DataTable IsLeader = da.GetDataTable(Sql); if (IsLeader.Rows[0]["IsLeader"].ToString() == "1") { //领导为依次审批或者会签 if (IsLeader.Rows[0]["IsAndOr"].ToString() == "1" || IsLeader.Rows[0]["IsAndOr"].ToString() == "2") { processIsEnd = true; } //领导为或签 else { Sql = ""; // 1 2 3 null Sql = $"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'"; //当前节点未完成 if (da.GetValue(Sql).ToString() != "0") { processIsEnd = false; result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } else { processIsEnd = true; } if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } } } //如果不是领导 if (IsLeader.Rows[0]["IsLeader"].ToString() != "1") { if (IsLeader.Rows[0]["IsAndOr"].ToString() == "1" || IsLeader.Rows[0]["IsAndOr"].ToString() == "2") { processIsEnd = true; } else { Sql = ""; // 1 2 3 null Sql = $"select count(*) from ApprovalComments where BillNo ='{traApprClass.BillNo}' and NodeNumber ='{int.Parse(nodeNumber) + 1}' and ApprovalStatus='0' and BillClassId='{traApprClass.BillClassId}'"; //当前节点未完成 if (da.GetValue(Sql).ToString() != "0") { processIsEnd = false; result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } else { processIsEnd = true; } if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作ApprovalComments表:" + Sql + "\r\n"); } } } if (processIsEnd) { //更新单据消息id与返回内容 Sql = "update TravelReq set isauditing='2',auditingdate=getdate() where billno='" + traApprClass.BillNo + "'"; if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作TravelReq表:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); //给当前节点以前的人及申请人发送通知,通知已驳回,并改变出差申请表中的状态 sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{traApprClass.BillNo}' and BillClassId='{traApprClass.BillClassId}'"; logComments = da.GetDataTable(sql); //"【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; for (int i = 0; i < logComments.Rows.Count; i++) { if (i > 0) { logcoments.Append(","); //piddept.Append(","); } sql = ""; sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{logComments.Rows[i]["ApprovalID"].ToString()}'"; //piddept.Append(da.GetValue(sql).ToString()); logcoments.Append(logComments.Rows[i]["ApprovalName"].ToString() + ":" + logComments.Rows[i]["ApprovalComments"].ToString()); } urlcsjson = ddUrl + $"/shenpi/index.html?billno={traApprClass.BillNo}&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n申请人: " + traApprClass.OperatorName + "【出差】\r\n审批意见: " + logcoments.ToString() + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n发送通知出入参=>CsJson:" + CsJson + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } } } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new BankDbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); string JsonData = CsJson; //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("其他费用报销申请日志", "\r\n入参:" + CsJson + "\r\n"); } string ddMessageId = string.Empty; OtherCostSQModel otherCostSQModel = new OtherCostSQModel(); otherCostSQModel = (OtherCostSQModel)JsonConvert.DeserializeObject(CsJson, typeof(OtherCostSQModel)); string path = context.Request.Path.Replace("Approval/OtherCostSQ.ashx", "othercostsq"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + otherCostSQModel.Sign + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != otherCostSQModel.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } string NodeInfo = JsonConvert.SerializeObject(otherCostSQModel.NodeInfo).Replace(",{\"AType\":\"\",\"PersonId\":\"select\",\"PersonName\":\"请选择\"}", ""); try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token billTypeNo = "100520005055"; billNoPro = "QTFY"; ProName = "EXPEREFERdd"; typeName = "其他费用"; typeUrl = ddUrl + "/qtfyui/shenpi/index.html?billno="; string fqrall = otherCostSQModel.DDOperatorId; string jnumber = otherCostSQModel.ApplPers; string sqr = otherCostSQModel.OperatorName; if (otherCostSQModel.IsInsteadApply == "1") { fqrall = fqrall + "," + otherCostSQModel.InsteadOperatorGuid; sqr = "【代】" + otherCostSQModel.InsteadOperatorName; jnumber = da.GetValue($"select top 1 employeecode from flowemployee where ddid = '{otherCostSQModel.InsteadOperatorGuid}'").ToString(); } else { otherCostSQModel.OperatorGuid = da.GetValue($"select top 1 guid from flowemployee where ddid = '{fqrall}' and orgcode ='{otherCostSQModel.DeptCode}'").ToString(); } #region 获取申请流水号 Sql = "select dbo.GetBillNo('" + billTypeNo + "','" + jnumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = billNoPro + jnumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新其他费用单号出错(DD9002)\",\"errcode\":1}"); return; } string guid = string.Empty; #endregion 获取申请流水号 #region 获取用户guid Sql = $"select top 1 a.GUID,b.TotalAmount,b.OffDay from operators a left join (select sum(TotalAmount) TotalAmount, sum(OffDay) OffDay from ExpetravDetail where billno = '[申请号]' group by billno) b on 1 = 1 where a.code = '[工号]'"; Sql = Sql.Replace("[申请号]", otherCostSQModel.BillNo).Replace("[工号]", jnumber); obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; operatorGuid = dt.Rows[0]["GUID"].ToString(); #endregion 获取用户guid if (otherCostSQModel.NodeInfo.Length == 0) { //自动同意 //更新单据消息id与返回内容 #region 保存信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into EXPEOTHER(BillNo,BillDate,FeeType,OperatorGuid,FlowEmployeeGuid,ProcessNodeInfo,ApplPers,DDOperatorId,JsonData,BillCount,FeeAmount,DeptName,DeptCode,NoCountFee,BearOrga,AppendixUrl,Urls,IsInsteadApply,InsteadOperatorGuid,PictureUrl,Notes) Values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append(otherCostSQModel.FeeType).Append("','") .Append(operatorGuid).Append("','") .Append(otherCostSQModel.OperatorGuid).Append("','") .Append(NodeInfo).Append("','") .Append(jnumber).Append("','") .Append(otherCostSQModel.DDOperatorId).Append("','") .Append(JsonData).Append("','") .Append(otherCostSQModel.BillCount).Append("','") .Append(otherCostSQModel.FeeAmount).Append("','") .Append(otherCostSQModel.DeptName).Append("','") .Append(otherCostSQModel.DeptCode).Append("','") .Append(otherCostSQModel.NoCountFee).Append("','") .Append(otherCostSQModel.BearOrga).Append("','") .Append(otherCostSQModel.AppendixUrl).Append("','") .Append(JsonConvert.SerializeObject(otherCostSQModel.Urls)).Append("','") .Append(otherCostSQModel.IsInsteadApply).Append("','") .Append(otherCostSQModel.InsteadOperatorGuid).Append("','") .Append(otherCostSQModel.PictureUrl).Append("','") .Append(otherCostSQModel.Notes) .Append("')"); sqlList.Add(sqlTou.ToString()); for (int i = 0; i < otherCostSQModel.OtherCostSQModels.Count; i++) { guid = Guid.NewGuid().ToString(); Sql = string.Empty; Sql = $"insert into ExpeOtherDetail(BillNo,GUID,BillCount,BillAmount,FeeTypeDetail) values('{billno}','{guid}','{otherCostSQModel.OtherCostSQModels[i].Count}','{otherCostSQModel.OtherCostSQModels[i].Amount}','{otherCostSQModel.OtherCostSQModels[i].FType}')"; sqlList.Add(Sql); ToolsClass.TxtLog("其他费用报销申请日志", "\r\n操作ExpeotherDetail表:" + Sql + "\r\n"); } if (isWrite == "1") { ToolsClass.TxtLog("其他费用报销申请日志", "\r\n操作Expeother表:" + sqlTou.ToString() + "\r\n"); } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存信息 #region 调用提交存储过程 keyValuePairs = CommonHelper.sqlPro(billno, billTypeNo, operatorGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("其他费用报销申请日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); sqlList.Clear(); Sql = "delete from EXPEOTHER where BillNo='" + billno + "'"; sqlList.Add(Sql); obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); return; } #endregion 调用提交存储过程 Sql = "update EXPEOTHER set IsSp='1',auditingdate=getdate() where billno='" + billno + "'"; ToolsClass.TxtLog("其他费用报销申请日志", "\r\n操作EXPEOTHER表:" + Sql.ToString() + "\r\n"); obj = da.ExecSql(Sql); Sql = ""; #region 发送工作通知消息 urlcsjson = typeUrl + "" + $"{billno}&BillClassId={otherCostSQModel.BillClassId}&showmenu=false"; urlcsjson = System.Web.HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + sqr + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + otherCostSQModel.FeeAmount + "¥ 发票: " + otherCostSQModel.BillCount + " 张\r\n申请日期: " + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n备注: " + otherCostSQModel.Notes + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); var xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); ddMessageId = xxtzClass2.task_id.ToString(); #endregion 发送工作通知消息 context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } //获取第一级流程的人员信息 NodeInfoDetailPerson[] NodeInfodetailPeople = otherCostSQModel.NodeInfo[0].NodeInfoDetails[0].Persons; //从入参中得到审批人及抄送人的信息 //指定人员的id列表 StringBuilder piddept = new StringBuilder(); string sql = ""; for (int i = 0; i < NodeInfodetailPeople.Length; i++) { if (i > 0) { piddept.Append(","); } //判断传空 if (NodeInfodetailPeople[i].PersonId != "select" && NodeInfodetailPeople[i].PersonId != "") { sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'"; piddept.Append(da.GetValue(sql).ToString()); } } #region 保存信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into EXPEOTHER(BillNo,BillDate,FeeType,OperatorGuid,FlowEmployeeGuid,JsonData,ProcessNodeInfo,ApplPers,DDOperatorId,BillCount,FeeAmount,DeptName,DeptCode,NoCountFee,BearOrga,AppendixUrl,Urls,IsInsteadApply,InsteadOperatorGuid,PictureUrl,Notes) Values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append(otherCostSQModel.FeeType).Append("','") .Append(operatorGuid).Append("','") .Append(otherCostSQModel.OperatorGuid).Append("','") .Append(JsonData).Append("','") .Append(NodeInfo).Append("','") .Append(jnumber).Append("','") .Append(otherCostSQModel.DDOperatorId).Append("','") .Append(otherCostSQModel.BillCount).Append("','") .Append(otherCostSQModel.FeeAmount).Append("','") .Append(otherCostSQModel.DeptName).Append("','") .Append(otherCostSQModel.DeptCode).Append("','") .Append(otherCostSQModel.NoCountFee).Append("','") .Append(otherCostSQModel.BearOrga).Append("','") .Append(otherCostSQModel.AppendixUrl).Append("','") .Append(JsonConvert.SerializeObject(otherCostSQModel.Urls)).Append("','") .Append(otherCostSQModel.IsInsteadApply).Append("','") .Append(otherCostSQModel.InsteadOperatorGuid).Append("','") .Append(otherCostSQModel.PictureUrl).Append("','") .Append(otherCostSQModel.Notes) .Append("')"); sqlList.Add(sqlTou.ToString()); for (int i = 0; i < otherCostSQModel.OtherCostSQModels.Count; i++) { guid = Guid.NewGuid().ToString(); Sql = string.Empty; Sql = $"insert into ExpeOtherDetail(BillNo,GUID,BillCount,BillAmount,FeeTypeDetail) values('{billno}','{guid}','{otherCostSQModel.OtherCostSQModels[i].Count}','{otherCostSQModel.OtherCostSQModels[i].Amount}','{otherCostSQModel.OtherCostSQModels[i].FType}')"; sqlList.Add(Sql); ToolsClass.TxtLog("其他费用报销申请日志", "\r\n操作ExpeotherDetail表:" + Sql + "\r\n"); } if (isWrite == "1") { ToolsClass.TxtLog("其他费用报销申请日志", "\r\n操作Expeother表:" + sqlTou.ToString() + "\r\n"); } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存信息 #region 调用提交存储过程 keyValuePairs = CommonHelper.sqlPro(billno, billTypeNo, operatorGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("其他费用报销申请日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); sqlList.Clear(); Sql = "delete from EXPEOTHER where BillNo='" + billno + "'"; sqlList.Add(Sql); obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); return; } #endregion 调用提交存储过程 #region 发送工作通知消息 urlcsjson = typeUrl + "" + $"{billno}&BillClassId={otherCostSQModel.BillClassId}&showmenu=false"; urlcsjson = System.Web.HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + sqr + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + otherCostSQModel.FeeAmount + "¥ 发票: " + otherCostSQModel.BillCount + " 张\r\n申请日期: " + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n备注: " + otherCostSQModel.Notes + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); ddMessageId = xxtzClass.task_id.ToString(); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请,消息通知失败(DD9004)\",\"errcode\":1}"); return; } #endregion 发送工作通知消息 //保存流程信息到comments表 sqlList.Clear(); for (int i = 0; i < NodeInfodetailPeople.Length; i++) { sqlTou.Clear(); if (NodeInfodetailPeople[i].PersonId != "select") { sqlTou.Append("insert into ApprovalComments(CommentsId,BillClassId,BillNo,ApprovalID,ApprovalName,ApprovalComments,ApprovalStatus,DDMessageId,AType,ApprovalDate,IsAndOr,IsLeader,PersonType,NodeNumber) values('").Append(Guid.NewGuid().ToString()).Append("','") .Append(otherCostSQModel.BillClassId).Append("','") .Append(billno).Append("','") .Append(NodeInfodetailPeople[i].PersonId).Append("','") .Append(NodeInfodetailPeople[i].PersonName).Append("','")//内部数据库用户GUID .Append("").Append("','") .Append("0").Append("','") .Append(ddMessageId).Append("','") .Append(NodeInfodetailPeople[i].AType).Append("','") .Append(DateTime.Now).Append("','") .Append(otherCostSQModel.NodeInfo[0].NodeInfoDetails[0].IsAndOr).Append("','") .Append(otherCostSQModel.NodeInfo[0].NodeInfoDetails[0].IsLeader).Append("','") .Append(otherCostSQModel.NodeInfo[0].NodeInfoType).Append("','") .Append("2").Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("其他费用报销申请日志", "\r\n操作ApprovalComments表:" + sqlTou.ToString() + "\r\n"); } } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存申请信息节点信息出错(DD6002)\",\"errcode\":1}"); return; } path = context.Request.Path.Replace("Approval/OtherCostSQ.ashx", "othercostsp"); //验证请求sign sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); //如果下个是抄送人 TaskFactory taskFactory = new TaskFactory(); if (otherCostSQModel.NodeInfo[0].NodeInfoType == "3") { //根据数据开启多个线程调用审批接口 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "othercostsp"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = billno, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsSp = "3", DDOperatorId = otherCostSQModel.InsteadOperatorGuid, OperatorName = otherCostSQModel.InsteadOperatorName, BillClassId = otherCostSQModel.BillClassId, FeeType = otherCostSQModel.FeeType, Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } }); } if (otherCostSQModel.NodeInfo[0].NodeInfoType == "2") { DataRow[] dataRows = null; sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{billno}' and BillClassId='{otherCostSQModel.BillClassId}' and ApprovalStatus ='1'"; DataTable logComments = da.GetDataTable(sql); //如果下个环节中的人在之前已同意,自动调用此接口同意完成审批 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { dataRows = logComments.Select("ApprovalID ='" + NodeInfodetailPeople[i].PersonId + "'"); //如果之前已经同意或者是发起人 if (dataRows.Length != 0 || da.GetValue($"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'").ToString() == otherCostSQModel.InsteadOperatorGuid) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "othercostsp"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = billno, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsSp = "1", DDOperatorId = otherCostSQModel.InsteadOperatorGuid, OperatorName = otherCostSQModel.InsteadOperatorName, BillClassId = otherCostSQModel.BillClassId, AuditingIdea = "同意", FeeType = otherCostSQModel.FeeType, Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } } }); } //如果是撤回重新提交的,删除之前的单子 if (!string.IsNullOrEmpty(otherCostSQModel.OldBillNo)) { da.ExecSql($"delete ExpeOtherDetail where billno = '{otherCostSQModel.OldBillNo}'"); da.ExecSql($"delete EXPEOTHER where billno = '{otherCostSQModel.OldBillNo}'"); da.ExecSql($"delete approvalcomments where billno = '{otherCostSQModel.OldBillNo}'"); da.Dispose(); ToolsClass.TxtLog("其他费用报销申请日志", "\r\n删除旧单据:" + $"delete ExpeOtherDetail where billno = '{otherCostSQModel.OldBillNo}'" + $"delete EXPEOTHER where billno = '{otherCostSQModel.OldBillNo}'" + "\r\n"); } context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "\",\"errcode\":1}"); context.Response.End(); } }
private string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string FileUrl = ToolsClass.GetConfig("FileUrl"); GetMulParams getMulParams = new GetMulParams(); string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); SqlHelper = new BankDbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } string result = string.Empty; string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n申请审批入参:" + CsJson + "\r\n"); } string IsLocalHost = "0"; //前端传入数据 TravelApprovalMul traApprClass = new TravelApprovalMul(); traApprClass = (TravelApprovalMul)JsonConvert.DeserializeObject(CsJson, typeof(TravelApprovalMul)); IsLocalHost = traApprClass.IsLocalHost == null ? "0" : traApprClass.IsLocalHost; string path1 = context.Request.Path.Replace("Approval/MedConfigAuditing.ashx", "medconfigauditing"); //验证请求sign string sign = ToolsClass.md5(signUrl + path1 + "Romens1/DingDing2" + path1, 32); ToolsClass.TxtLog("生成的sign", "生成的" + "sign1:" + sign + "传入的sign" + traApprClass.Sign + "\r\n 后台字符串:" + signUrl + path1 + "Romens1/DingDing2" + path1); if (sign != traApprClass.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } try { if (traApprClass.IsSp == "1") { audiIdea = "同意"; } else if (traApprClass.IsSp == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } billTypeNo = "2018121301"; ProName = "MedConfigAuditing"; typeUrl = ddUrl + "/yibao/shenpi/index.html?billno="; //获取当前单号的发起人和待报销人 string fqrall = traApprClass.DDOperatorId; var fqr = SqlHelper.GetDataTable($"select OperatorGuid,REFERGUID,IsSp from MedConfig where BillNo = '{traApprClass.BillNo}'"); if (traApprClass.DDOperatorId != traApprClass.ReferDDID) { fqrall = fqrall + "," + traApprClass.ReferDDID; } #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } audiName = userXqClass.name; #endregion 获取用户详情 #region 获取用户guid Sql = $"select Guid from operators where code = '[工号]'"; Sql = Sql.Replace("[申请号]", traApprClass.BillNo).Replace("[工号]", userXqClass.jobnumber); obj = SqlHelper.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; AuditingGuid = dt.Rows[0]["Guid"].ToString(); #endregion 获取用户guid if (SqlHelper.GetValue($"select issp from medconfig where billno ='{traApprClass.BillNo}'").ToString() != "0") { context.Response.Write("{\"errmsg\":\"当前单据已经审核,不允许重复审核!\",\"errcode\":1}"); return; } XXTZ xxtzClass2 = new XXTZ(); if (audiIdea == "同意" || audiIdea == "抄送") { bool processIsEnd = true; // processIsEnd = CommonHelper.SaveComments(traApprClass, userXqClass, nodeNumber, context, ddUrl, "医保及三方授权审批日志", out result); //可以给下个人发送消息 if (processIsEnd) //如果当前流程节点走完 { billno = traApprClass.BillNo; keyValuePairs = CommonHelper.sqlPro(SqlHelper.GetValue($"select guid from MedConfig where billno = '{billno}'").ToString(), billTypeNo, AuditingGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); Sql = "update MedConfig set IsSp='0' where billno='" + traApprClass.BillNo + "'"; obj = SqlHelper.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批状态出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); return; } Sql = $"update MedConfig set IsSp='1',AuditingReason = '{traApprClass.AuditingIdea}' where billno='{traApprClass.BillNo}'"; FhJson = ToolsClass.ApiFun("POST", ymadk + "SetSignFile", "{\"BillNo\":\"" + traApprClass.BillNo + "\"}").Replace(@"\", "/"); FileLocationJson jgobj = (FileLocationJson)JsonConvert.DeserializeObject(FhJson, typeof(FileLocationJson)); ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n操作MedConfig表:" + Sql.ToString() + "\r\n"); obj = SqlHelper.ExecSql(Sql); urlcsjson = typeUrl + traApprClass.BillNo + $"&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); DDMsgModelLink link = new DDMsgModelLink { messageUrl = $"dingtalk://dingtalkclient/page/link?url={ urlcsjson}&pc_slide=true", picUrl = "@", text = $"\r\n单号为[{billno}]的单据已同意", title = $"已{audiIdea }【{ audiName }】" }; DDMsgModelLinkMsg dDMsg = new DDMsgModelLinkMsg { link = link, msgtype = "link" }; string ddmsgModel = JsonConvert.SerializeObject(new DDMsgModel { agent_id = agentId, userid_list = fqrall, msg = dDMsg }); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, ddmsgModel); if (isWrite == "1") { ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n审批发送通知Json:" + ddmsgModel + "\r\n返回json:\r\n" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } string sqlm = CommonHelper.CreateRandomCode(5); string nowdownurl = FileUrl + jgobj.fileurl; string xzdzqd = ddUrl + "/yibao/download/index.html"; Sql = $"update MedConfig set DownUrlInfo = '{sqlm},{nowdownurl}' where billno='{traApprClass.BillNo}'"; SqlHelper.ExecSql(Sql); DDMsgModelText dDMsgModelText = new DDMsgModelText { agent_id = agentId, userid_list = fqrall, msg = new DDMsgModelTextMsg { msgtype = "text", text = new text { content = "授权文件下载地址,请点击下载:\r\n" + xzdzqd + "\r\n提取验证码: " + sqlm } } }; ddmsgModel = JsonConvert.SerializeObject(dDMsgModelText); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, ddmsgModel); } else { ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } //if (IsLocalHost == "0") //{ // result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); // ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); // context.Response.Write(result); //} //else //{ // result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); // ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); // context.Response.Write(result); //} result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } if (audiIdea == "驳回") { Sql = $"update MedConfig set IsSp='2',auditingdate=getdate(),AuditingGuid = '{AuditingGuid}',AuditingReason = '{traApprClass.AuditingIdea}' where billno='{traApprClass.BillNo }'"; obj = SqlHelper.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n操作MedConfig表:" + Sql); //给当前节点以前的人及申请人发送通知,通知已驳回 urlcsjson = typeUrl + traApprClass.BillNo + $"&BillClassId={traApprClass.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); DDMsgModelLink link = new DDMsgModelLink { messageUrl = $"dingtalk://dingtalkclient/page/link?url={urlcsjson}&pc_slide=true", picUrl = "@", text = $"\r\n单号为【{traApprClass.BillNo}】的单据没有审核通过。\r\n 拒绝原因:{traApprClass.AuditingIdea}。", title = $"已{audiIdea }【{ audiName }】" }; DDMsgModelLinkMsg dDMsg = new DDMsgModelLinkMsg { link = link, msgtype = "link" }; string ddmsgModel = JsonConvert.SerializeObject(new DDMsgModel { agent_id = agentId, userid_list = fqrall, msg = dDMsg }); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, ddmsgModel); if (isWrite == "1") { ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n发送通知出入参Json:" + ddmsgModel); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的医保及三方授权消息通知失败(DD6004)\",\"errcode\":1}"); return; } } result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); //if (IsLocalHost == "0") //{ // result = JsonConvert.SerializeObject(getMulParams.resultGetMulParams(ymadk, traApprClass.DDAuditingId, ddUrl, SqlHelper)); // ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); // context.Response.Write(result); //} //else //{ // result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); // ToolsClass.TxtLog("医保及三方授权审批日志", "\r\n返回前端信息:" + result + "\r\n"); // context.Response.Write(result); //} return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "\",\"errcode\":1}"); context.Response.End(); } }
private string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); string JsonData = CsJson; //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请日志", "\r\n申请入参:" + CsJson + "\r\n"); } TAMcs tAMcs = new TAMcs(); tAMcs = (TAMcs)JsonConvert.DeserializeObject(CsJson, typeof(TAMcs)); string path = context.Request.Path.Replace("Approval/TAMultistage.ashx", "tam"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + tAMcs.Sign + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != tAMcs.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } //string s = JsonConvert.SerializeObject(tAMcs.NodeInfo); string NodeInfo = JsonConvert.SerializeObject(tAMcs.NodeInfo).Replace(",{\"AType\":\"\",\"PersonId\":\"select\",\"PersonName\":\"请选择\"}", ""); if (tAMcs.Detail.Length <= 0) { context.Response.Write("{\"errmsg\":\"行程不允许为空,请添加行程(DD6001)\",\"errcode\":1}"); return; } try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + tAMcs.DDOperatorId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取申请人详细信息报错(DD6003)\",\"errcode\":1}"); return; } operatorName = userXqClass.name; #endregion 获取用户详情 #region 获取用户guid Sql = "select top 1 guid from FlowEmployee where employeecode='" + userXqClass.jobnumber + $"' and orgcode='{tAMcs.DeptCode}'"; obj = da.GetValue(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } operatorGuid = obj.ToString(); #endregion 获取用户guid #region 获取申请流水号 Sql = "select dbo.GetBillNo('DDTrvelReq','" + userXqClass.jobnumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = "CL" + userXqClass.jobnumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } if (tAMcs.NodeInfo.Length == 0) { //自动同意 #region 保存行程信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into TravelReq(BillNo,TravelReason,Notes,DeptName,DeptCode,DDOperatorId,OperatorGuid,Urls,ProcessNodeInfo,BillDate,IsAuditing,OperatorName,AppendixUrl,PictureUrl) values('").Append(billno).Append("','") .Append(tAMcs.TravelReason).Append("','") .Append(tAMcs.Notes).Append("','") .Append(tAMcs.DeptName).Append("','") .Append(tAMcs.DeptCode).Append("','") .Append(tAMcs.DDOperatorId).Append("','") .Append(operatorGuid).Append("','") //内部数据库用户GUID .Append(JsonConvert.SerializeObject(tAMcs.Urls)).Append("','") .Append(NodeInfo).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append("0").Append("','") .Append(operatorName).Append("','"); if (string.IsNullOrEmpty(tAMcs.AppendixUrl)) { sqlTou.Append("未传").Append("','"); } else { sqlTou.Append(tAMcs.AppendixUrl).Append("','"); } if (string.IsNullOrEmpty(tAMcs.PictureUrl)) { sqlTou.Append("未传").Append("')"); } else { sqlTou.Append(tAMcs.PictureUrl).Append("')"); } sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请日志", "\r\n操作TravelReq表:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into TravelReqDetail(BillNo,Guid,TranMode,OtherTranMode,IsReturn,DepaCity,DepaCity1,DepaCity2,DestCity,DestCity1,DestCity2,StartDate,EndDate,Hours,Days,BearOrga,CustCode,CustName,Peers,PeersName) values('"); for (int i = 0; i < tAMcs.Detail.Length; i++) { sqlTi.Clear(); sqlTi.Append(sqlTou.ToString()).Append(billno).Append("','") .Append(Guid.NewGuid().ToString()).Append("','") .Append(tAMcs.Detail[i].TranMode).Append("','") .Append(tAMcs.Detail[i].OtherTranMode).Append("','") .Append(tAMcs.Detail[i].IsReturn).Append("','") .Append(tAMcs.Detail[i].DepaCity).Append("','") .Append(tAMcs.Detail[i].DepaCity1).Append("','") .Append(tAMcs.Detail[i].DepaCity2).Append("','") .Append(tAMcs.Detail[i].DestCity).Append("','") .Append(tAMcs.Detail[i].DestCity1).Append("','") .Append(tAMcs.Detail[i].DestCity2).Append("','") .Append(tAMcs.Detail[i].StartDate).Append(":01','") .Append(tAMcs.Detail[i].EndDate).Append(":01','") .Append(tAMcs.Detail[i].Hours).Append("','") .Append(tAMcs.Detail[i].Days).Append("','") .Append(tAMcs.Detail[i].BearOrga).Append("','") .Append(tAMcs.Detail[i].CustCode).Append("','") .Append(tAMcs.Detail[i].CustName).Append("','") .Append(tAMcs.Detail[i].Peers).Append("','") .Append(tAMcs.Detail[i].PeersName).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请日志", "操作TravelReq表:" + sqlTi.ToString() + "\r\n"); } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存行程信息 Sql = "update TravelReq set isauditing='1',auditingdate=getdate() where billno='" + billno + "'"; if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请审批日志", "\r\n操作TravelReq表:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); urlcsjson = ddUrl + $"/shenpi/index.html?billno={billno}&BillClassId={tAMcs.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + tAMcs.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + operatorName + "的【出差】申请\",\"text\":\"出发日期: " + tAMcs.Detail[0].StartDate.Substring(0, 10) + "\r\n返程日期: " + tAMcs.Detail[0].EndDate.Substring(0, 10) + "\r\n事由: " + tAMcs.TravelReason + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } #endregion 获取申请流水号 //获取第一级流程的人员信息 NodeInfoDetailPerson[] NodeInfodetailPeople = tAMcs.NodeInfo[0].NodeInfoDetails[0].Persons; //从入参中得到审批人及抄送人的信息 //指定人员的id列表 StringBuilder piddept = new StringBuilder(); string sql = ""; for (int i = 0; i < NodeInfodetailPeople.Length; i++) { if (i > 0) { piddept.Append(","); } //判断传空 if (NodeInfodetailPeople[i].PersonId != "select" && NodeInfodetailPeople[i].PersonId != "") { sql = $"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'"; piddept.Append(da.GetValue(sql).ToString()); } } #region 保存行程信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into TravelReq(BillNo,TravelReason,Notes,DeptName,DeptCode,DDOperatorId,OperatorGuid,JsonData,Urls,ProcessNodeInfo,BillDate,IsAuditing,OperatorName,AppendixUrl,PictureUrl) values('").Append(billno).Append("','") .Append(tAMcs.TravelReason).Append("','") .Append(tAMcs.Notes).Append("','") .Append(tAMcs.DeptName).Append("','") .Append(tAMcs.DeptCode).Append("','") .Append(tAMcs.DDOperatorId).Append("','") .Append(operatorGuid).Append("','") //内部数据库用户GUID .Append(JsonData).Append("','") .Append(JsonConvert.SerializeObject(tAMcs.Urls)).Append("','") .Append(NodeInfo).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append("0").Append("','") .Append(operatorName).Append("','"); if (string.IsNullOrEmpty(tAMcs.AppendixUrl)) { sqlTou.Append("未传").Append("','"); } else { sqlTou.Append(tAMcs.AppendixUrl).Append("','"); } if (string.IsNullOrEmpty(tAMcs.PictureUrl)) { sqlTou.Append("未传").Append("')"); } else { sqlTou.Append(tAMcs.PictureUrl).Append("')"); } sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请日志", "\r\n操作TravelReq表:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into TravelReqDetail(BillNo,Guid,TranMode,OtherTranMode,IsReturn,DepaCity,DepaCity1,DepaCity2,DestCity,DestCity1,DestCity2,StartDate,EndDate,Hours,Days,BearOrga,CustCode,CustName,Peers,PeersName) values('"); for (int i = 0; i < tAMcs.Detail.Length; i++) { sqlTi.Clear(); sqlTi.Append(sqlTou.ToString()).Append(billno).Append("','") .Append(Guid.NewGuid().ToString()).Append("','") .Append(tAMcs.Detail[i].TranMode).Append("','") .Append(tAMcs.Detail[i].OtherTranMode).Append("','") .Append(tAMcs.Detail[i].IsReturn).Append("','") .Append(tAMcs.Detail[i].DepaCity).Append("','") .Append(tAMcs.Detail[i].DepaCity1).Append("','") .Append(tAMcs.Detail[i].DepaCity2).Append("','") .Append(tAMcs.Detail[i].DestCity).Append("','") .Append(tAMcs.Detail[i].DestCity1).Append("','") .Append(tAMcs.Detail[i].DestCity2).Append("','") .Append(tAMcs.Detail[i].StartDate).Append(":01','") .Append(tAMcs.Detail[i].EndDate).Append(":01','") .Append(tAMcs.Detail[i].Hours).Append("','") .Append(tAMcs.Detail[i].Days).Append("','") .Append(tAMcs.Detail[i].BearOrga).Append("','") .Append(tAMcs.Detail[i].CustCode).Append("','") .Append(tAMcs.Detail[i].CustName).Append("','") .Append(tAMcs.Detail[i].Peers).Append("','") .Append(tAMcs.Detail[i].PeersName).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请日志", "操作TravelReq表:" + sqlTi.ToString() + "\r\n"); } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存行程信息 //保存流程信息到comments表 sqlList.Clear(); for (int i = 0; i < NodeInfodetailPeople.Length; i++) { sqlTou.Clear(); if (NodeInfodetailPeople[i].PersonId != "select") { sqlTou.Append("insert into ApprovalComments(CommentsId,BillClassId,BillNo,ApprovalID,ApprovalName,ApprovalComments,ApprovalStatus,AType,ApprovalDate,IsAndOr,IsLeader,PersonType,NodeNumber) values('").Append(Guid.NewGuid().ToString()).Append("','") .Append(tAMcs.BillClassId).Append("','") .Append(billno).Append("','") .Append(NodeInfodetailPeople[i].PersonId).Append("','") .Append(NodeInfodetailPeople[i].PersonName).Append("','")//内部数据库用户GUID .Append("").Append("','") .Append("0").Append("','") .Append(NodeInfodetailPeople[i].AType).Append("','") .Append(DateTime.Now).Append("','") .Append(tAMcs.NodeInfo[0].NodeInfoDetails[0].IsAndOr).Append("','") .Append(tAMcs.NodeInfo[0].NodeInfoDetails[0].IsLeader).Append("','") .Append(tAMcs.NodeInfo[0].NodeInfoType).Append("','") .Append("2").Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("多级审批出差申请日志", "\r\n操作ApprovalComments表:" + sqlTou.ToString() + "\r\n"); } } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请节点信息出错(DD6002)\",\"errcode\":1}"); return; } #region 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; urlcsjson = ddUrl + $"/shenpi/index.html?billno={billno}&BillClassId={tAMcs.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + piddept.ToString() + "," + tAMcs.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + operatorName + "的【出差】申请\",\"text\":\"出发日期: " + tAMcs.Detail[0].StartDate.Substring(0, 10) + "\r\n返程日期: " + tAMcs.Detail[0].EndDate.Substring(0, 10) + "\r\n事由: " + tAMcs.TravelReason + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); ToolsClass.TxtLog("多级审批出差申请日志", "发起申请" + CsJson.ToString() + "\r\n"); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion 发送工作通知消息 path = context.Request.Path.Replace("Approval/TAMultistage.ashx", "tasp"); //验证请求sign sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); TaskFactory taskFactory = new TaskFactory(); if (tAMcs.NodeInfo[0].NodeInfoType == "3") { //根据数据开启多个线程调用审批接口 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "tasp"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = billno, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsAuditing = "3", DDOperatorId = tAMcs.DDOperatorId, OperatorName = operatorName, BillClassId = tAMcs.BillClassId, Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } }); } if (tAMcs.NodeInfo[0].NodeInfoType == "2") { DataRow[] dataRows = null; sql = ""; sql = $"select ApprovalComments,ApprovalName,ApprovalID from ApprovalComments where BillNo ='{billno}' and BillClassId='{tAMcs.BillClassId}' and ApprovalStatus ='1'"; DataTable logComments = da.GetDataTable(sql); //如果下个环节中的人在之前已同意,自动调用此接口同意完成审批 taskFactory.StartNew(() => { for (int i = 0; i < NodeInfodetailPeople.Length; i++) { dataRows = logComments.Select("ApprovalID ='" + NodeInfodetailPeople[i].PersonId + "'"); //如果之前已经同意或者是发起人 if (dataRows.Length != 0 || da.GetValue($"select distinct DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'").ToString() == tAMcs.DDOperatorId) { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(ymadk + "tasp"); webrequest.Method = "post"; new Action(() => { fasongqingqiu ad = new fasongqingqiu { BillNo = billno, DDAuditingId = da.GetValue($"select distinct ddid from FlowEmployee where employeecode='{NodeInfodetailPeople[i].PersonId}'").ToString(), IsAuditing = "1", DDOperatorId = tAMcs.DDOperatorId, OperatorName = operatorName, BillClassId = tAMcs.BillClassId, AuditingIdea = "同意", Sign = sign }; byte[] postdatabyte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ad)); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); using (var httpWebResponse = webrequest.GetResponse()) using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream())) { String ret = responseStream.ReadToEnd(); } }).Invoke(); } } }); } context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { ToolsClass.TxtLog("DDLog", "\r\nTxfApproval=>入参:" + CsJson + "\r\n"); context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfApproval=>入参:" + CsJson + "\r\n"); } TxfClass txfClass = new TxfClass(); txfClass = (TxfClass)JsonConvert.DeserializeObject(CsJson, typeof(TxfClass)); try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion if (txfClass.FeeType == "01") { //市内交通费 billTypeNo = "100520005015"; billNoPro = "JTF"; ProName = "EXPEREFER"; typeName = "交通费"; typeUrl = ddUrl + "/jtfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "02") { //通讯费 billTypeNo = "100520005020"; billNoPro = "TXF"; ProName = "EXPEREFER"; typeName = "通讯费"; typeUrl = ddUrl + "/txfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "03") { //车辆费 billTypeNo = "100520005025"; billNoPro = "CLF"; ProName = "EXPEREFER"; typeName = "车辆费"; typeUrl = ddUrl + "/clui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "04") { //房租费 billTypeNo = "100520005030"; billNoPro = "FZ"; ProName = "EXPEREFER"; typeName = "房租费"; typeUrl = ddUrl + "/fzfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "05") { //水费 billTypeNo = "100520005035"; billNoPro = "SF"; ProName = "EXPEREFER"; typeName = "水费"; typeUrl = ddUrl + "/sfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "06") { //电费 billTypeNo = "100520005040"; billNoPro = "DF"; ProName = "EXPEREFER"; typeName = "电费"; typeUrl = ddUrl + "/dfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "00") { //招待费 billTypeNo = "100520005010"; billNoPro = "ZDF"; ProName = "EXPEREFER"; typeName = "招待费"; typeUrl = ddUrl + "/zdfui/shenpi/index.html?billno="; } else { context.Response.Write("{\"errmsg\":\"提交的报销类型不存在(DD9001)\",\"errcode\":1}"); return; } #region 获取申请流水号 Sql = "select dbo.GetBillNo('" + billTypeNo + "','" + txfClass.ApplPers + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); operatorGuid = txfClass.OperatorGuid; if (billno == "1") { billno = billNoPro + txfClass.ApplPers + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新通信费单号出错(DD9002)\",\"errcode\":1}"); return; } #endregion #region 保存信息 sqlList.Clear(); sqlTou.Clear(); if (txfClass.FeeType == "00") { sqlTou.Append("insert into EXPEENTEMENT(BillNo,BillDate,OperatorGuid,ApplPers,DDOperatorId,BillCount,FeeAmount,NoCountFee,BearOrga,AppendixUrl,PictureUrl,Notes,SelAuditingGuid,SelAuditingName,CopypersonID,CopyPersonName,CustCode) Values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd")).Append("','") .Append(txfClass.OperatorGuid).Append("','") .Append(txfClass.ApplPers).Append("','") .Append(txfClass.DDOperatorId).Append("','") .Append(txfClass.BillCount).Append("','") .Append(txfClass.FeeAmount).Append("','") .Append(txfClass.NoCountFee).Append("','") .Append(txfClass.BearOrga).Append("','") .Append(txfClass.AppendixUrl).Append("','") .Append(txfClass.PictureUrl).Append("','") .Append(txfClass.Notes).Append("','") .Append(txfClass.SelAuditingGuid).Append("','") .Append(txfClass.SelAuditingName).Append("','") .Append(txfClass.CopypersonID).Append("','") .Append(txfClass.CopyPersonName).Append("','") .Append(txfClass.CustCode).Append("')"); } else { sqlTou.Append("insert into EXPEOTHER(BillNo,BillDate,FeeType,OperatorGuid,ApplPers,DDOperatorId,BillCount,FeeAmount,NoCountFee,BearOrga,AppendixUrl,PictureUrl,Notes,SelAuditingGuid,SelAuditingName,CopypersonID,CopyPersonName) Values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd")).Append("','") .Append(txfClass.FeeType).Append("','") .Append(txfClass.OperatorGuid).Append("','") .Append(txfClass.ApplPers).Append("','") .Append(txfClass.DDOperatorId).Append("','") .Append(txfClass.BillCount).Append("','") .Append(txfClass.FeeAmount).Append("','") .Append(txfClass.NoCountFee).Append("','") .Append(txfClass.BearOrga).Append("','") .Append(txfClass.AppendixUrl).Append("','") .Append(txfClass.PictureUrl).Append("','") .Append(txfClass.Notes).Append("','") .Append(txfClass.SelAuditingGuid).Append("','") .Append(txfClass.SelAuditingName).Append("','") .Append(txfClass.CopypersonID).Append("','") .Append(txfClass.CopyPersonName).Append("')"); } sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfApproval=>insert:" + sqlTou.ToString() + "\r\n"); } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion #region 调用提交存储过程 if (!sqlPro()) { //招待费 if (txfClass.FeeType == "00") { sqlList.Clear(); Sql = "delete from EXPEENTEMENT where BillNo='" + billno + "'"; sqlList.Add(Sql); } else { sqlList.Clear(); Sql = "delete from EXPEOTHER where BillNo='" + billno + "'"; sqlList.Add(Sql); } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + ProResult + "(DD9003)\",\"errcode\":1}"); return; } #endregion #region 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + txfClass.SelAuditingGuid + "," + txfClass.CopypersonID + "," + txfClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + "" + billno + "\",\"picUrl\":\"@\",\"title\":\"" + txfClass.OperatorName + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + txfClass.FeeAmount + "¥ 发票: " + txfClass.BillCount + " 张\r\n申请日期: " + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n备注: " + txfClass.Notes + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请,消息通知失败(DD9004)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>入参:" + CsJson + "\r\n"); } CLFBX clfbxClass = new CLFBX(); clfbxClass = (CLFBX)JsonConvert.DeserializeObject(CsJson, typeof(CLFBX)); clfbxClass.Notes = Regex.Replace(clfbxClass.Notes, @"[\n\r]", "").Replace("\\", ""); if (clfbxClass.ExpeTravDetail.Length <= 0) { context.Response.Write("{\"errmsg\":\"费用明细不允许为空,请添加费用明细(DD7001)\",\"errcode\":1}"); return; } try { operatorGuid = clfbxClass.OperatorGuid; #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion if (clfbxClass.isRe == "1")//是否需要生产新的申请号 { #region 获取申请流水号 Sql = "select dbo.GetBillNo('DDTrvelReq','" + clfbxClass.JobNumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = "CL" + clfbxClass.JobNumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } billno = billno + "_B"; #endregion } else { billno = clfbxClass.BillNo; } #region 保存信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into ExpeTrav(BillNo,BillDate,Notes,OperatorGuid,Applpers,DDOperatorId,BearOrga,CostType,NoCountFee,SelAuditingGuid,CopyPerson,SelAuditingName,CopyPersonName,AppendixUrl,PictureUrl) values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd")).Append("','") .Append(clfbxClass.Notes).Append("','") .Append(clfbxClass.OperatorGuid).Append("','") .Append(clfbxClass.JobNumber).Append("','") .Append(clfbxClass.DDOperatorId).Append("','") .Append(clfbxClass.BearOrga).Append("','") .Append(clfbxClass.CostType).Append("','") .Append(clfbxClass.NoCountFee).Append("','") .Append(clfbxClass.SelAuditingGuid).Append("','") .Append(clfbxClass.CopyPerson).Append("','") .Append(clfbxClass.SelAuditingName).Append("','") .Append(clfbxClass.CopyPersonName).Append("','") .Append(clfbxClass.AppendixUrl).Append("','") .Append(clfbxClass.PictureUrl).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insertTou:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into ExpetravDetail(TripNo,BillNo,Guid,DepaDate,RetuDate,DepaCity,DestCity,DepaCity1,DestCity1,CustCode,DetailNo,AlloDay,OffDay,AlloPric,AlloAmount,OtherFee,TranMode,TranCount,TranAmount,GasAmount,HsrAmount,AccoCount,AccoAmount,CityTrafCount,CityTraAmont,TotalAmount) values('"); for (int i = 0; i < clfbxClass.ExpeTravDetail.Length; i++) { AccoCount = "0"; // 住宿票张数 AccoAmount = "0"; // 住宿金额 CityTrafCount = "0"; // 市内交通票张数 CityTraAmount = "0"; // 市内交通金额 oneSumAmount = 0; //第一行的和 SumMony = SumMony + Double.Parse(clfbxClass.ExpeTravDetail[i].TotalAmount); sqlTiPro.Clear(); detailNo = detailNo + 1; TripNo = 1; sqlTiPro.Append(sqlTou.ToString()).Append(i + 1).Append("','") .Append(billno).Append("',newid(),'") .Append(clfbxClass.ExpeTravDetail[i].DepaDate).Append("','") .Append(clfbxClass.ExpeTravDetail[i].RetuDate).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DepaCity3).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DestCity3).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DepaCity1).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DestCity1).Append("','") .Append(clfbxClass.ExpeTravDetail[i].CustCode).Append("','"); for (int j = 0; j < clfbxClass.ExpeTravDetail[i].PList.Length; j++) { if (j == 0) { sqlTi.Clear(); sqlTi.Append(sqlTiPro.ToString()).Append(detailNo) .Append("','").Append(clfbxClass.ExpeTravDetail[i].AlloDay) .Append("','").Append(clfbxClass.ExpeTravDetail[i].OffDay) .Append("','").Append(clfbxClass.ExpeTravDetail[i].AlloPric) .Append("','").Append(clfbxClass.ExpeTravDetail[i].AlloAmount) .Append("','").Append(clfbxClass.ExpeTravDetail[i].OtherFee); oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].AlloAmount) + Double.Parse(clfbxClass.ExpeTravDetail[i].OtherFee); } if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "火车票" || clfbxClass.ExpeTravDetail[i].PList[j].FType == "飞机票" || clfbxClass.ExpeTravDetail[i].PList[j].FType == "汽车票" || clfbxClass.ExpeTravDetail[i].PList[j].FType == "轮船票") { if (TripNo == 1) { sqlTi.Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0"); oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].Amount); detailNo = detailNo + 1; TripNo = TripNo + 1; } else { sqlTi2.Clear(); sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0','0','0','0','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].SumAmount) .Append("')"); sqlList.Add(sqlTi2.ToString()); detailNo = detailNo + 1; TripNo = TripNo + 1; ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insertTi:" + sqlTi2.ToString() + "\r\n"); } } else if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "自驾") { if (TripNo == 1) { sqlTi.Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].GasAmount) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].HsrAmount); oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].SumAmount); detailNo = detailNo + 1; TripNo = TripNo + 1; } else { sqlTi2.Clear(); sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].GasAmount).Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].HsrAmount).Append("','0','0','0','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].SumAmount) .Append("')"); sqlList.Add(sqlTi2.ToString()); detailNo = detailNo + 1; TripNo = TripNo + 1; ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insertTi:" + sqlTi2.ToString() + "\r\n"); } } else if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "住宿票") { AccoCount = clfbxClass.ExpeTravDetail[i].PList[j].Count; AccoAmount = clfbxClass.ExpeTravDetail[i].PList[j].Amount; oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].Amount); } else if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "市内交通票") { CityTrafCount = clfbxClass.ExpeTravDetail[i].PList[j].Count; CityTraAmount = clfbxClass.ExpeTravDetail[i].PList[j].Amount; oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].Amount); } } sqlTi.Append("','").Append(AccoCount) .Append("','").Append(AccoAmount) .Append("','").Append(CityTrafCount) .Append("','").Append(CityTraAmount) .Append("','").Append(oneSumAmount).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insert:" + sqlTi.ToString() + "\r\n"); } } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion #region 调用提交存储过程 if (!sqlPro()) { aList.Clear(); Sql = "delete from ExpeTrav where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from ExpetravDetail where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from CUSTIMPLLOG where SourceBill='" + billno + "'"; aList.Add(Sql); obj = da.ExecSql(aList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + ProResult + "(DD9003)\",\"errcode\":1}"); return; } #endregion #region 差旅费报销 申请 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + clfbxClass.SelAuditingGuid + "," + clfbxClass.CopyPerson + "," + clfbxClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + ddUrl + "/clfui/shenpi/index.html?billno=" + billno + "\",\"picUrl\":\"@\",\"title\":\"" + clfbxClass.OperatorName + "的【差旅费】报销申请\",\"text\":\"金额: " + SumMony + " ¥\r\n行程: " + clfbxClass.ExpeTravDetail[0].DepaCity1 + " - " + clfbxClass.ExpeTravDetail[0].DestCity1 + "\r\n申请日期: " + System.DateTime.Now.ToString("yyyy-MM-dd") + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的差旅费报销申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nSendMsg=>入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApproval traApprClass = new TravelApproval(); traApprClass = (TravelApproval)JsonConvert.DeserializeObject(CsJson, typeof(TravelApproval)); try { #region 设置消息跳转链接地址 if (traApprClass.FeeType == "01") { //市内交通费; typeName = "交通费"; typeUrl = ddUrl + "/jtfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "02") { //通讯费 typeName = "通讯费"; typeUrl = ddUrl + "/txfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "03") { //车辆费 typeName = "车辆费"; typeUrl = ddUrl + "/clui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "04") { //房租费 typeName = "房租费"; typeUrl = ddUrl + "/fzfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "05") { //水费 typeName = "水费"; typeUrl = ddUrl + "/sfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "06") { //电费 typeName = "电费"; typeUrl = ddUrl + "/dfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "11") { //出差 typeName = "出差"; typeUrl = ddUrl + "/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "12") { //差旅费 typeName = "差旅费"; typeUrl = ddUrl + "/clfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "00") { //招待费 typeName = "招待费"; typeUrl = ddUrl + "/zdfui/shenpi/index.html?billno="; } else { context.Response.Write("{\"errmsg\":\"提交的申请类型不存在(DD9001)\",\"errcode\":1}"); return; } #endregion #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取通知信息字段 //出差 if (traApprClass.FeeType == "11") { Sql = "select a.TravelReason,convert(varchar(20),min(b.StartDate),23) StartDate,convert(varchar(20),max(EndDate),23) EndDate from TravelReq a left join TravelReqDetail b on a.billno=b.billno where a.billno='" + traApprClass.BillNo + "' group by a.billno,a.TravelReason"; } //差旅费报销申请 else if (traApprClass.FeeType == "12") { Sql = "select top 1 A.DepaCity1 DepaCity,A.DestCity1 DestCity,b.TranAmount,convert(varchar(20),c.BillDate,23) BillDate from ExpeTravDetail A left join (select billno,sum(TotalAmount) TranAmount from ExpeTravDetail group by billno) b on a.billno=b.billno left join ExpeTrav c on a.BillNo=c.BillNo where a.BillNo = '" + traApprClass.BillNo + "' order by a.depadate"; } //招待费 else if (traApprClass.FeeType == "00") { Sql = "select FeeAmount,BillCount,convert(varchar(20),ReferDate,23) BillDate,Notes from EXPEENTEMENT where billno='" + traApprClass.BillNo + "'"; } //其他费用 else { Sql = "select FeeAmount,BillCount,convert(varchar(20),ReferDate,23) BillDate,Notes from EXPEOTHER where billno='" + traApprClass.BillNo + "'"; } obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD9002)\",\"errcode\":1}"); return; } dt = obj as DataTable; if (dt.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"申请信息不存在(DD9003)\",\"errcode\":1}"); return; } #endregion #region 发送工作通知消息 //出差 if (traApprClass.FeeType == "11") { CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.CopyPerson + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"" + traApprClass.OperatorName + "的【" + typeName + "】申请\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n返程日期: " + dt.Rows[0]["EndDate"].ToString() + "\r\n事由: " + dt.Rows[0]["TravelReason"].ToString() + "\"}}}"; } //差旅费报销申请 else if (traApprClass.FeeType == "12") { CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.CopyPerson + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"" + traApprClass.OperatorName + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + dt.Rows[0]["TranAmount"].ToString() + " ¥\r\n行程: " + dt.Rows[0]["DepaCity"].ToString() + " - " + dt.Rows[0]["DestCity"].ToString() + "\r\n申请日期: " + dt.Rows[0]["BillDate"].ToString() + "\"}}}"; } //其他费用 else { CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.CopyPerson + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"" + traApprClass.OperatorName + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + dt.Rows[0]["FeeAmount"].ToString() + "¥ 发票: " + dt.Rows[0]["BillCount"].ToString() + " 张\r\n申请日期: " + dt.Rows[0]["BillDate"].ToString() + "\r\n备注: " + dt.Rows[0]["Notes"].ToString() + "\"}}}"; } url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nSendMsg=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); } XXTZ xxtzClass2 = new XXTZ(); xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请消息通知失败(DD9004)\",\"errcode\":1}"); return; } #endregion #region 更新 将转发人拼接在抄送人字段后面 //出差 if (traApprClass.FeeType == "11") { Sql = "update TravelReq set CopyPerson=(case when isnull(CopyPerson,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPerson+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } //差旅费报销申请 else if (traApprClass.FeeType == "12") { Sql = "update ExpeTrav set CopyPerson=(case when isnull(CopyPerson,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPerson+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } //招待费 else if (traApprClass.FeeType == "00") { Sql = "update EXPEENTEMENT set CopyPersonID=(case when isnull(CopyPersonID,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPersonID+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } //其他费用 else { Sql = "update EXPEOTHER set CopyPersonID=(case when isnull(CopyPersonID,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPersonID+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新抄送人信息出错(DD9005)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD9006)\",\"errcode\":1}"); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new BankDbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); string JsonData = CsJson; //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n入参:" + CsJson + "\r\n"); } string ddMessageId = string.Empty; MedConfigReqRequest configReqRequest = new MedConfigReqRequest(); configReqRequest = (MedConfigReqRequest)JsonConvert.DeserializeObject(CsJson, typeof(MedConfigReqRequest)); string path = context.Request.Path.Replace("Approval/MedConfigReq.ashx", "medconfigreq"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); ToolsClass.TxtLog("生成的sign", "生成的" + sign + "传入的sign" + configReqRequest.Sign + "\r\n 后台字符串:" + signUrl + path + "Romens1/DingDing2" + path); if (sign != configReqRequest.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } string NodeInfo = JsonConvert.SerializeObject(configReqRequest.NodeInfo).Replace(",{\"AType\":\"\",\"PersonId\":\"select\",\"PersonName\":\"请选择\"}", ""); try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token ProName = "MedConfigRefer"; typeName = "医保及三方授权"; typeUrl = ddUrl + "/yibao/shenpi/index.html?billno="; string fqrall = configReqRequest.OperatorDDID; //根据ddid获取内部系统中operator中guid //获得提交人信息dt var referinfo = da.GetDataTable($"select a.GUID,a.code,a.name from operators a where code = (select top 1 employeecode from flowemployee where ddid = '{configReqRequest.ReferDDID}')"); if (referinfo.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"当前操作人员未在operators或者flowemployee中维护信息!请联系信息部解决\",\"errcode\":1}"); return; } string ReferGuid = referinfo.Rows[0]["GUID"].ToString(); string jnumber = referinfo.Rows[0]["code"].ToString(); string sqr = configReqRequest.OperatorName; if (configReqRequest.IsInsteadApply == "1") { fqrall = fqrall + "," + configReqRequest.ReferDDID; sqr = "【代替】" + configReqRequest.InsteadOperatorName; jnumber = da.GetValue($"select top 1 employeecode from flowemployee where ddid = '{configReqRequest.ReferDDID}'").ToString(); } operatorGuid = da.GetValue($"select a.GUID from operators a where code = (select top 1 employeecode from flowemployee where ddid = '{configReqRequest.OperatorDDID}')").ToString(); #region 获取申请流水号 Sql = $"select dbo.GetBillNo('{billTypeNo}','{jnumber}',getdate())"; billno = da.GetValue(Sql).ToString(); if (billno == "1") { billno = billNoPro + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新医保授权申请单号出错(DD9002)\",\"errcode\":1}"); return; } string guid = string.Empty; #endregion 获取申请流水号 #region 暂不会有没有审批人现象 //if (configReqRequest.NodeInfo.Count == 0) //{ // //自动同意 // //更新单据消息id与返回内容 // #region 保存信息 // sqlList.Clear(); // sqlTou.Clear(); // sqlTou.Append("insert into EXPEOTHER(BillNo,BillDate,FeeType,OperatorGuid,FlowEmployeeGuid,ProcessNodeInfo,ApplPers,DDOperatorId,JsonData,BillCount,FeeAmount,DeptName,DeptCode,NoCountFee,BearOrga,AppendixUrl,Urls,IsInsteadApply,InsteadOperatorGuid,PictureUrl,Notes) Values('") // .Append(billno).Append("','") // .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") // .Append(configReqRequest.FeeType).Append("','") // .Append(operatorGuid).Append("','") // .Append(configReqRequest.OperatorGuid).Append("','") // .Append(NodeInfo).Append("','") // .Append(jnumber).Append("','") // .Append(configReqRequest.DDOperatorId).Append("','") // .Append(JsonData).Append("','") // .Append(configReqRequest.BillCount).Append("','") // .Append(configReqRequest.FeeAmount).Append("','") // .Append(configReqRequest.DeptName).Append("','") // .Append(configReqRequest.DeptCode).Append("','") // .Append(configReqRequest.NoCountFee).Append("','") // .Append(configReqRequest.BearOrga).Append("','") // .Append(configReqRequest.AppendixUrl).Append("','") // .Append(JsonConvert.SerializeObject(configReqRequest.Urls)).Append("','") // .Append(configReqRequest.IsInsteadApply).Append("','") // .Append(configReqRequest.InsteadOperatorGuid).Append("','") // .Append(configReqRequest.PictureUrl).Append("','") // .Append(configReqRequest.Notes) // .Append("')"); // sqlList.Add(sqlTou.ToString()); // for (int i = 0; i < configReqRequest.configReqRequests.Count; i++) // { // guid = Guid.NewGuid().ToString(); // Sql = string.Empty; // Sql = $"insert into ExpeOtherDetail(BillNo,GUID,BillCount,BillAmount,FeeTypeDetail) values('{billno}','{guid}','{configReqRequest.configReqRequests[i].Count}','{configReqRequest.configReqRequests[i].Amount}','{configReqRequest.configReqRequests[i].FType}')"; // sqlList.Add(Sql); // ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n操作ExpeotherDetail表:" + Sql + "\r\n"); // } // if (isWrite == "1") // { // ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n操作Expeother表:" + sqlTou.ToString() + "\r\n"); // } // obj = da.ExecSql(sqlList); // if (obj == null) // { // context.Response.Write("{\"errmsg\":\"保存申请信息出错(DD6002)\",\"errcode\":1}"); // return; // } // #endregion 保存信息 // #region 调用提交存储过程 // keyValuePairs = CommonHelper.sqlPro(billno, billTypeNo, operatorGuid, ProName); // if (keyValuePairs["ReturnValue"].ToString() != "0") // { // ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); // sqlList.Clear(); // Sql = "delete from EXPEOTHER where BillNo='" + billno + "'"; // sqlList.Add(Sql); // obj = da.ExecSql(sqlList); // if (obj == null) // { // context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); // return; // } // context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "(DD9003)\",\"errcode\":1}"); // return; // } // #endregion 调用提交存储过程 // Sql = "update EXPEOTHER set IsSp='1',auditingdate=getdate() where billno='" + billno + "'"; // ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n操作EXPEOTHER表:" + Sql.ToString() + "\r\n"); // obj = da.ExecSql(Sql); // Sql = ""; // #region 发送工作通知消息 // urlcsjson = typeUrl + "" + $"{billno}&BillClassId={configReqRequest.BillClassId}&showmenu=false"; // urlcsjson = System.Web.HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); // url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; // CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + fqrall + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + "dingtalk://dingtalkclient/page/link?url=" + urlcsjson + "&pc_slide=true\",\"picUrl\":\"@\",\"title\":\"" + sqr + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + configReqRequest.FeeAmount + "¥ 发票: " + configReqRequest.BillCount + " 张\r\n申请日期: " + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n备注: " + configReqRequest.Notes + "\"}}}"; // FhJson = ToolsClass.ApiFun("POST", url, CsJson); // var xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); // ddMessageId = xxtzClass2.task_id.ToString(); // #endregion 发送工作通知消息 // context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); // return; //} #endregion 暂不会有没有审批人现象 //获取第一级流程的人员信息 NodeInfoDetailPerson[] NodeInfodetailPeople = configReqRequest.NodeInfo[0].NodeInfoDetails[0].Persons; //从入参中得到审批人及抄送人的信息 //指定人员的id列表 StringBuilder piddept = new StringBuilder(); string sql = ""; for (int i = 0; i < NodeInfodetailPeople.Length; i++) { if (i > 0) { piddept.Append(","); } //判断传空 if (NodeInfodetailPeople[i].PersonId != "select" && NodeInfodetailPeople[i].PersonId != "") { sql = $"select top 1 DDId from FlowEmployee where EmployeeCode ='{NodeInfodetailPeople[i].PersonId}'"; piddept.Append(da.GetValue(sql).ToString()); } } #region 保存信息 string medGuid = Guid.NewGuid().ToString(); sqlList.Clear(); sqlTou.Clear(); string mainMedConfig = $"insert into MedConfig (Guid,BillNo,BillDate,BillTime,CusGuid,CusCode,CusName,MedType,ProductType,IsAuditing,AuditingGuid,AuditingDate,OperatorGuid,Notes,YXQ,YXQFlag,iswrite,YXQType,ISREFER,REFERGUID,REFERDATE,FileUrl,AuditingReason,IsSp) Values('{medGuid}','{billno}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}','{DateTime.Now.ToString(" HH:mm:ss")}',null,'{configReqRequest.CustCode}','{configReqRequest.CustName}','{configReqRequest.MedTypeList}','{configReqRequest.ProductType}','0',null,null,'{operatorGuid}','{configReqRequest.Notes}',null,null,'0','{configReqRequest.YXQType}','0',null,null,null,null,0)"; if (isWrite == "1") { ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n操作MedConfig表:" + mainMedConfig + "\r\n"); } obj = da.ExecSql(mainMedConfig); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion 保存信息 #region 调用提交存储过程 keyValuePairs = CommonHelper.sqlPro(medGuid, billTypeNo, ReferGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); sqlList.Clear(); Sql = "delete from MedConfig where guid='" + medGuid + "'"; obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"执行存储过程报错\",\"errcode\":1}"); return; } #endregion 调用提交存储过程 #region 发送工作通知消息 urlcsjson = typeUrl + "" + $"{billno}&BillClassId={configReqRequest.BillClassId}&showmenu=false"; urlcsjson = System.Web.HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; DDMsgModelLink link = new DDMsgModelLink { messageUrl = $"dingtalk://dingtalkclient/page/link?url={ urlcsjson}&pc_slide=true", picUrl = "@", text = $"\r\n申请日期:{ DateTime.Now.ToString("yyyy-MM-dd")}\r\n备注:{configReqRequest.Notes}", title = $"{sqr }发起的【医保及三方支付申请】" }; DDMsgModelLinkMsg dDMsg = new DDMsgModelLinkMsg { link = link, msgtype = "link" }; string ddmsgModel = JsonConvert.SerializeObject(new DDMsgModel { agent_id = agentId, userid_list = piddept.ToString() + "," + fqrall, msg = dDMsg }); FhJson = ToolsClass.ApiFun("POST", url, ddmsgModel); ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n发送通知json:" + ddmsgModel + "\r\n"); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); ddMessageId = xxtzClass.task_id.ToString(); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请,消息通知失败(DD9004)\",\"errcode\":1}"); return; } #endregion 发送工作通知消息 //如果是撤回重新提交的,删除之前的单子 //if (!string.IsNullOrEmpty(configReqRequest.OldBillNo)) //{ // da.ExecSql($"delete ExpeOtherDetail where billno = '{configReqRequest.OldBillNo}'"); // da.ExecSql($"delete EXPEOTHER where billno = '{configReqRequest.OldBillNo}'"); // da.ExecSql($"delete approvalcomments where billno = '{configReqRequest.OldBillNo}'"); // da.Dispose(); // ToolsClass.TxtLog("医保及三方授权申请日志", "\r\n删除旧单据:" + $"delete ExpeOtherDetail where billno = '{configReqRequest.OldBillNo}'" + $"delete EXPEOTHER where billno = '{configReqRequest.OldBillNo}'" + "\r\n"); //} context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + "\",\"errcode\":1}"); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } string ymadk = System.Configuration.ConfigurationManager.AppSettings["ymadk"].ToString() + "/"; string result = string.Empty; //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer SqlHelper = new BankDbHelper.SqlHelper("SqlServer", connectionString); string signUrl = ToolsClass.GetConfig("signUrl"); context.Response.ContentType = "text/plain"; //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { result = JsonConvert.SerializeObject(new PublicResult { errcode = "1", errmsg = "报文格式错误!" }); context.Response.Write(result); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ",").Replace("'", "‘").Replace("\t", ":").Replace("\r", ",").Replace("\n", ","); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("单据付款日志", $"\r\n单据付款入参:{CsJson}\r\n"); } string IsLocalHost = "0"; //前端传入数据 CashierPayModel payModel = new CashierPayModel(); payModel = (CashierPayModel)JsonConvert.DeserializeObject(CsJson, typeof(CashierPayModel)); IsLocalHost = payModel.IsLocalHost == null ? "0" : payModel.IsLocalHost; string path = context.Request.Path.Replace("Approval/CashierPay.ashx", "cashierpay"); //验证请求sign string sign = ToolsClass.md5(signUrl + path + "Romens1/DingDing2" + path, 32); if (sign != payModel.Sign) { context.Response.Write("{\"errmsg\":\"认证信息Sign不存在或者不正确!\",\"errcode\":1}"); return; } GetMulParams getMulParams = new GetMulParams(); try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion 获取access_token #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + payModel.DDOperatorId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } #endregion 获取用户详情 #region 获取用户guid Sql = $"select top 1 a.GUID,b.TotalAmount,b.OffDay from operators a left join (select sum(TotalAmount) TotalAmount, sum(OffDay) OffDay from ExpetravDetail where billno = '[申请号]' group by billno) b on 1 = 1 where a.code = '[工号]'"; Sql = Sql.Replace("[申请号]", payModel.BillNo).Replace("[工号]", userXqClass.jobnumber); obj = SqlHelper.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; operatorGuid = dt.Rows[0]["GUID"].ToString(); #endregion 获取用户guid XXTZ xxtzClass2 = new XXTZ(); StringBuilder piddept = new StringBuilder(); string sql = string.Empty; string uiPro = string.Empty; DataTable logComments = new DataTable(); StringBuilder logcoments = new StringBuilder(); switch (payModel.FeeType) { case "00": uiPro = "/zdfui"; billTypeNo = "100520005010"; break; case "01": uiPro = "/jtfui"; billTypeNo = "100520005015"; break; case "02": uiPro = "/txfui"; billTypeNo = "100520005020"; break; case "12": uiPro = "/clfui"; billTypeNo = "100520005005"; break; case "07": uiPro = "/qtfyui"; billTypeNo = "100520005055"; break; default: break; } //获取当前单号的发起人和待报销人 billno = payModel.BillNo; keyValuePairs = CommonHelper.sqlPro(billno, billTypeNo, operatorGuid, ProName); if (keyValuePairs["ReturnValue"].ToString() != "0") { ToolsClass.TxtLog("单据付款日志", "\r\n调用存储过程失败:" + keyValuePairs["ReturnMsg"].ToString() + "\r\n"); context.Response.Write("{\"errmsg\":\"" + keyValuePairs["ReturnMsg"].ToString() + "\",\"errcode\":1}"); return; } urlcsjson = ddUrl + $"{uiPro}/shenpi/index.html?billno={payModel.BillNo}&BillClassId={payModel.BillClassId}&showmenu=false"; urlcsjson = HttpUtility.UrlEncode(urlcsjson, System.Text.Encoding.UTF8); DDMsgModel dDMsgModel = new DDMsgModel { agent_id = agentId, userid_list = payModel.DDOperatorId + "," + payModel.DDPayId, msg = new DDMsgModelLinkMsg { msgtype = "link", link = new DDMsgModelLink { messageUrl = $"dingtalk://dingtalkclient/page/link?url={urlcsjson}&pc_slide=true", picUrl = "@", text = $"单据{payModel.BillNo}已付款", title = $"已付款{payModel.OperatorName}" } } }; string ddjsonmsgModel = JsonConvert.SerializeObject(dDMsgModel); url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, ddjsonmsgModel); if (isWrite == "1") { ToolsClass.TxtLog("单据付款日志", "\r\n发送通知调用钉钉api入参:" + ddjsonmsgModel + "\r\n出参:" + FhJson); } xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { switch (payModel.FeeType) { case "00": SqlHelper.ExecSql($"update EXPEENTEMENT set ISACCOUNT=0,ACCOUNTGUID='',ACCOUNTDate=null where BillNo = '{billno}' "); break; case "12": SqlHelper.ExecSql($"update ExpeTrav set ISACCOUNT=0,ACCOUNTGUID='',ACCOUNTDate=null where BillNo = '{billno}' "); break; default: SqlHelper.ExecSql($"update ExpeOther set ISACCOUNT=0,ACCOUNTGUID='',ACCOUNTDate=null where BillNo = '{billno}' "); break; } context.Response.Write("{\"errmsg\":\"您的单据付款消息通知失败(DD6004)\",\"errcode\":1}"); return; } result = JsonConvert.SerializeObject(new ResultGetMulParams { errcode = "0", errmsg = "", NextUrl = "" }); ToolsClass.TxtLog("单据付款日志", "\r\n返回前端信息:" + result + "\r\n"); context.Response.Write(result); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"" + ex.Message + ex.StackTrace + "\",\"errcode\":1}"); context.Response.End(); } }