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; } }
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(); } }
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 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(); } }