string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>入参:" + CsJson + "\r\n"); } CCSQ ccsqClass = new CCSQ(); ccsqClass = (CCSQ)JsonConvert.DeserializeObject(CsJson, typeof(CCSQ)); //ccsqClass.Notes = Regex.Replace(ccsqClass.Notes, @"[\n\r]", "").Replace("\\", ""); //ccsqClass.TravelReason = Regex.Replace(ccsqClass.TravelReason, @"[\n\r]", "").Replace("//", ""); if (ccsqClass.Detail.Length <= 0) { context.Response.Write("{\"errmsg\":\"行程不允许为空,请添加行程(DD6001)\",\"errcode\":1}"); return; } try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + ccsqClass.DDOperatorId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取申请人详细信息报错(DD6003)\",\"errcode\":1}"); return; } operatorName = userXqClass.name; #endregion #region 获取用户guid Sql = "select top 1 guid from Employee where employeecode='" + userXqClass.jobnumber + "'"; obj = da.GetValue(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } operatorGuid = obj.ToString(); #endregion #region 获取申请流水号 Sql = "select dbo.GetBillNo('DDTrvelReq','" + userXqClass.jobnumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = "CL" + userXqClass.jobnumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #endregion #region 保存行程信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into TravelReq(BillNo,TravelReason,Notes,DDOperatorId,OperatorGuid,BillDate,SelAuditingGuid,CopyPerson,OperatorName,SelAuditingName,CopyPersonName,AppendixUrl,PictureUrl) Values('").Append(billno).Append("','") .Append(ccsqClass.TravelReason).Append("','") .Append(ccsqClass.Notes).Append("','") .Append(ccsqClass.DDOperatorId).Append("','") .Append(operatorGuid).Append("','") //内部数据库用户GUID .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("','") .Append(ccsqClass.SelAuditingGuid).Append("','") .Append(ccsqClass.CopyPerson).Append("','") .Append(operatorName).Append("','") .Append(ccsqClass.SelAuditingName).Append("','") .Append(ccsqClass.CopyPersonName).Append("','") .Append(ccsqClass.AppendixUrl).Append("','") .Append(ccsqClass.PictureUrl).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>insert:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into TravelReqDetail(BillNo,Guid,TranMode,OtherTranMode,IsReturn,DepaCity,DepaCity1,DepaCity2,DestCity,DestCity1,DestCity2,StartDate,EndDate,Hours,Days,BearOrga,CustCode,CustName,Peers,PeersName) Values('"); for (int i = 0; i < ccsqClass.Detail.Length; i++) { sqlTi.Clear(); sqlTi.Append(sqlTou.ToString()).Append(billno).Append("','") .Append(Guid.NewGuid().ToString()).Append("','") .Append(ccsqClass.Detail[i].TranMode).Append("','") .Append(ccsqClass.Detail[i].OtherTranMode).Append("','") .Append(ccsqClass.Detail[i].IsReturn).Append("','") .Append(ccsqClass.Detail[i].DepaCity).Append("','") .Append(ccsqClass.Detail[i].DepaCity1).Append("','") .Append(ccsqClass.Detail[i].DepaCity2).Append("','") .Append(ccsqClass.Detail[i].DestCity).Append("','") .Append(ccsqClass.Detail[i].DestCity1).Append("','") .Append(ccsqClass.Detail[i].DestCity2).Append("','") .Append(ccsqClass.Detail[i].StartDate).Append(":01','") .Append(ccsqClass.Detail[i].EndDate).Append(":01','") .Append(ccsqClass.Detail[i].Hours).Append("','") .Append(ccsqClass.Detail[i].Days).Append("','") .Append(ccsqClass.Detail[i].BearOrga).Append("','") .Append(ccsqClass.Detail[i].CustCode).Append("','") .Append(ccsqClass.Detail[i].CustName).Append("','") .Append(ccsqClass.Detail[i].Peers).Append("','") .Append(ccsqClass.Detail[i].PeersName).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>insert:" + sqlTi.ToString() + "\r\n"); } } //执行SQL语句Insert obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion #region 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + ccsqClass.SelAuditingGuid + "," + ccsqClass.CopyPerson + "," + ccsqClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + ddUrl + "/shenpi/index.html?billno=" + billno + "\",\"picUrl\":\"@\",\"title\":\"" + operatorName + "的【出差】申请\",\"text\":\"出发日期: " + ccsqClass.Detail[0].StartDate.Substring(0, 10) + "\r\n返程日期: " + ccsqClass.Detail[0].EndDate.Substring(0, 10) + "\r\n事由: " + ccsqClass.TravelReason + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion #region 更新单据消息id与返回内容 //Sql = "update TravelReq set task_id='" + xxtzClass.task_id + "',request_id='" + xxtzClass.request_id + "',returnMsg='" + FhJson.ToString() + "' where billno='" + billno + "'"; //obj = da.ExecSql(Sql); //if (obj == null) //{ // if (isWrite == "1") // { // ToolsClass.TxtLog("DDLog", "\r\nTravelReq=>update:" + Sql.ToString() + "\r\n"); // } // context.Response.Write("{\"errmsg\":\"保存消息通知信息出错(DD6005)\",\"errcode\":1}"); // return; //} #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfAudi=>入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApproval traApprClass = new TravelApproval(); traApprClass = (TravelApproval)JsonConvert.DeserializeObject(CsJson, typeof(TravelApproval)); try { if (traApprClass.IsSp == "1") { audiIdea = "同意"; } else if (traApprClass.IsSp == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } if (traApprClass.FeeType == "01") { //市内交通费 billTypeNo = "100520005015"; ProName = "EXPEAUDITING"; typeName = "交通费"; typeUrl = ddUrl + "/jtfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "02") { //通讯费 billTypeNo = "100520005020"; ProName = "EXPEAUDITING"; typeName = "通讯费"; typeUrl = ddUrl + "/txfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "03") { //车辆费 billTypeNo = "100520005025"; ProName = "EXPEAUDITING"; typeName = "车辆费"; typeUrl = ddUrl + "/clui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "04") { //房租费 billTypeNo = "100520005030"; ProName = "EXPEAUDITING"; typeName = "房租费"; typeUrl = ddUrl + "/fzfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "05") { //水费 billTypeNo = "100520005035"; ProName = "EXPEAUDITING"; typeName = "水费"; typeUrl = ddUrl + "/sfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "06") { //电费 billTypeNo = "100520005040"; ProName = "EXPEAUDITING"; typeName = "电费"; typeUrl = ddUrl + "/dfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "00") { //招待费 billTypeNo = "100520005010"; ProName = "EXPEAUDITING"; typeName = "招待费"; typeUrl = ddUrl + "/zdfui/shenpi/index.html?billno="; } else { context.Response.Write("{\"errmsg\":\"提交的报销类型不存在(DD9001)\",\"errcode\":1}"); return; } #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } audiName = userXqClass.name; #endregion #region 获取用户guid if (traApprClass.FeeType == "00") { Sql = "select top 1 a.Guid,b.BillCount,b.FeeAmount from Employee a left join (select BillCount,FeeAmount from EXPEENTEMENT where billno = '[申请号]') b on 1 = 1 where a.employeecode = '[工号]'"; } else { Sql = "select top 1 a.Guid,b.BillCount,b.FeeAmount from Employee a left join (select BillCount,FeeAmount from EXPEOTHER where billno = '[申请号]') b on 1 = 1 where a.employeecode = '[工号]'"; } Sql = Sql.Replace("[申请号]", traApprClass.BillNo).Replace("[工号]", userXqClass.jobnumber); obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD6000)\",\"errcode\":1}"); return; } dt = obj as DataTable; AuditingGuid = dt.Rows[0]["Guid"].ToString(); #endregion #region 更新审批信息 if (traApprClass.FeeType == "00") { //更新单据消息id与返回内容 Sql = "update EXPEENTEMENT set IsSp='" + traApprClass.IsSp + "',auditingidea='" + traApprClass.AuditingIdea + "',DDAuditingId='" + traApprClass.DDAuditingId + "',auditingguid='" + AuditingGuid + "' where billno='" + traApprClass.BillNo + "'"; } else { //更新单据消息id与返回内容 Sql = "update EXPEOTHER set IsSp='" + traApprClass.IsSp + "',auditingidea='" + traApprClass.AuditingIdea + "',DDAuditingId='" + traApprClass.DDAuditingId + "',auditingguid='" + AuditingGuid + "' where billno='" + traApprClass.BillNo + "'"; } if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfAudi=>update:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #endregion #region 调用审核存储过程 if (traApprClass.IsSp == "1") { billno = traApprClass.BillNo; if (!sqlPro()) { if (traApprClass.FeeType == "00") { Sql = "update EXPEENTEMENT set IsSp='0',auditingidea=null,DDAuditingId=null,auditingguid=null where billno='" + traApprClass.BillNo + "'"; } else { Sql = "update EXPEOTHER set IsSp='0',auditingidea=null,DDAuditingId=null,auditingguid=null where billno='" + traApprClass.BillNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批状态出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + ProResult + "(DD9003)\",\"errcode\":1}"); return; } } #endregion #region 发送工作通知消息 CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.DDAuditingId + "," + traApprClass.CopyPerson + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + "" + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"金额: " + dt.Rows[0]["FeeAmount"].ToString() + "¥ 发票: " + dt.Rows[0]["BillCount"].ToString() + "张\r\n申请人: " + traApprClass.OperatorName + "【" + typeName + "】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfAudi=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); } XXTZ xxtzClass2 = new XXTZ(); xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApproval traApprClass = new TravelApproval(); traApprClass = (TravelApproval)JsonConvert.DeserializeObject(CsJson, typeof(TravelApproval)); try { if (traApprClass.IsAuditing == "1") { audiIdea = "同意"; } else if (traApprClass.IsAuditing == "2") { audiIdea = "驳回"; } else { audiIdea = "抄送"; } #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取用户详情 url = "https://oapi.dingtalk.com/user/get?access_token=" + access_token + "&userid=" + traApprClass.DDAuditingId; FhJson = ToolsClass.ApiFun("GET", url, ""); GetUserXq userXqClass = new GetUserXq(); userXqClass = (GetUserXq)JsonConvert.DeserializeObject(FhJson, typeof(GetUserXq)); errcode = userXqClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取审批人详细信息报错(DD6003)\",\"errcode\":1}"); return; } audiName = userXqClass.name; #endregion #region 获取用户guid Sql = "select top 1 a.guid,b.StartDate,b.EndDate from FlowEmployee a left join (select convert(varchar(20), min(b.StartDate), 23) StartDate,convert(varchar(20), max(EndDate), 23) EndDate from TravelReq a left join TravelReqDetail b on a.billno = b.billno where a.billno = '" + traApprClass.BillNo + "' group by a.billno) b on 1 = 1 where a.employeecode = '" + userXqClass.jobnumber + "'"; obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD9002)\",\"errcode\":1}"); return; } dt = obj as DataTable; if (dt.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"申请信息不存在(DD9003)\",\"errcode\":1}"); return; } AuditingGuid = dt.Rows[0]["guid"].ToString(); #endregion #region 发送工作通知消息 CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.DDAuditingId + "," + traApprClass.CopyPerson + "," + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + ddUrl + "/shenpi/index.html?billno=" + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "【" + audiName + "】\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n申请人: " + traApprClass.OperatorName + "【出差】\r\n审批意见: " + traApprClass.AuditingIdea + "\"}}}"; url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); } XXTZ xxtzClass2 = new XXTZ(); xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion #region 发送普通会话消息 //if (traApprClass.Cid != "" && traApprClass.Cid != null) //{ // CsJson = "{\"cid\":\"" + traApprClass.Cid + "\",\"sender\":\"" + traApprClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"http://oa.romens.cn:8090/shenpi/index.html?billno=" + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"已" + audiIdea + "\",\"text\":\"" + audiName + audiIdea + "了审批\"}}}"; // url = "https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + access_token; // FhJson = ToolsClass.ApiFun("POST", url, CsJson); // if (isWrite == "1") // { // ToolsClass.TxtLog("DDLog", "\r\nProInfo=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); // } // XXTZ xxtzClass = new XXTZ(); // xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); // errcode = xxtzClass.errcode; // if (errcode != 0) // { // context.Response.Write("{\"errmsg\":\"您的出差申请消息通知失败(DD6004)\",\"errcode\":1}"); // return; // } //} #endregion #region 更新审批信息 //更新单据消息id与返回内容 Sql = "update TravelReq set isauditing='" + traApprClass.IsAuditing + "',auditingdate=getdate(),auditingidea='" + traApprClass.AuditingIdea + "',DDAuditingId='" + traApprClass.DDAuditingId + "',auditingguid='" + AuditingGuid + "',auditingname='" + audiName + "' where billno='" + traApprClass.BillNo + "'"; if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>update:" + Sql.ToString() + "\r\n"); } obj = da.ExecSql(Sql); if (obj == null) { if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nProInfo=>update:" + Sql.ToString() + "\r\n"); } context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { ToolsClass.TxtLog("DDLog", "\r\nTxfApproval=>入参:" + CsJson + "\r\n"); context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfApproval=>入参:" + CsJson + "\r\n"); } TxfClass txfClass = new TxfClass(); txfClass = (TxfClass)JsonConvert.DeserializeObject(CsJson, typeof(TxfClass)); try { #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion if (txfClass.FeeType == "01") { //市内交通费 billTypeNo = "100520005015"; billNoPro = "JTF"; ProName = "EXPEREFER"; typeName = "交通费"; typeUrl = ddUrl + "/jtfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "02") { //通讯费 billTypeNo = "100520005020"; billNoPro = "TXF"; ProName = "EXPEREFER"; typeName = "通讯费"; typeUrl = ddUrl + "/txfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "03") { //车辆费 billTypeNo = "100520005025"; billNoPro = "CLF"; ProName = "EXPEREFER"; typeName = "车辆费"; typeUrl = ddUrl + "/clui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "04") { //房租费 billTypeNo = "100520005030"; billNoPro = "FZ"; ProName = "EXPEREFER"; typeName = "房租费"; typeUrl = ddUrl + "/fzfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "05") { //水费 billTypeNo = "100520005035"; billNoPro = "SF"; ProName = "EXPEREFER"; typeName = "水费"; typeUrl = ddUrl + "/sfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "06") { //电费 billTypeNo = "100520005040"; billNoPro = "DF"; ProName = "EXPEREFER"; typeName = "电费"; typeUrl = ddUrl + "/dfui/shenpi/index.html?billno="; } else if (txfClass.FeeType == "00") { //招待费 billTypeNo = "100520005010"; billNoPro = "ZDF"; ProName = "EXPEREFER"; typeName = "招待费"; typeUrl = ddUrl + "/zdfui/shenpi/index.html?billno="; } else { context.Response.Write("{\"errmsg\":\"提交的报销类型不存在(DD9001)\",\"errcode\":1}"); return; } #region 获取申请流水号 Sql = "select dbo.GetBillNo('" + billTypeNo + "','" + txfClass.ApplPers + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); operatorGuid = txfClass.OperatorGuid; if (billno == "1") { billno = billNoPro + txfClass.ApplPers + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='" + billTypeNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新通信费单号出错(DD9002)\",\"errcode\":1}"); return; } #endregion #region 保存信息 sqlList.Clear(); sqlTou.Clear(); if (txfClass.FeeType == "00") { sqlTou.Append("insert into EXPEENTEMENT(BillNo,BillDate,OperatorGuid,ApplPers,DDOperatorId,BillCount,FeeAmount,NoCountFee,BearOrga,AppendixUrl,PictureUrl,Notes,SelAuditingGuid,SelAuditingName,CopypersonID,CopyPersonName,CustCode) Values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd")).Append("','") .Append(txfClass.OperatorGuid).Append("','") .Append(txfClass.ApplPers).Append("','") .Append(txfClass.DDOperatorId).Append("','") .Append(txfClass.BillCount).Append("','") .Append(txfClass.FeeAmount).Append("','") .Append(txfClass.NoCountFee).Append("','") .Append(txfClass.BearOrga).Append("','") .Append(txfClass.AppendixUrl).Append("','") .Append(txfClass.PictureUrl).Append("','") .Append(txfClass.Notes).Append("','") .Append(txfClass.SelAuditingGuid).Append("','") .Append(txfClass.SelAuditingName).Append("','") .Append(txfClass.CopypersonID).Append("','") .Append(txfClass.CopyPersonName).Append("','") .Append(txfClass.CustCode).Append("')"); } else { sqlTou.Append("insert into EXPEOTHER(BillNo,BillDate,FeeType,OperatorGuid,ApplPers,DDOperatorId,BillCount,FeeAmount,NoCountFee,BearOrga,AppendixUrl,PictureUrl,Notes,SelAuditingGuid,SelAuditingName,CopypersonID,CopyPersonName) Values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd")).Append("','") .Append(txfClass.FeeType).Append("','") .Append(txfClass.OperatorGuid).Append("','") .Append(txfClass.ApplPers).Append("','") .Append(txfClass.DDOperatorId).Append("','") .Append(txfClass.BillCount).Append("','") .Append(txfClass.FeeAmount).Append("','") .Append(txfClass.NoCountFee).Append("','") .Append(txfClass.BearOrga).Append("','") .Append(txfClass.AppendixUrl).Append("','") .Append(txfClass.PictureUrl).Append("','") .Append(txfClass.Notes).Append("','") .Append(txfClass.SelAuditingGuid).Append("','") .Append(txfClass.SelAuditingName).Append("','") .Append(txfClass.CopypersonID).Append("','") .Append(txfClass.CopyPersonName).Append("')"); } sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nTxfApproval=>insert:" + sqlTou.ToString() + "\r\n"); } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion #region 调用提交存储过程 if (!sqlPro()) { //招待费 if (txfClass.FeeType == "00") { sqlList.Clear(); Sql = "delete from EXPEENTEMENT where BillNo='" + billno + "'"; sqlList.Add(Sql); } else { sqlList.Clear(); Sql = "delete from EXPEOTHER where BillNo='" + billno + "'"; sqlList.Add(Sql); } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + ProResult + "(DD9003)\",\"errcode\":1}"); return; } #endregion #region 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + txfClass.SelAuditingGuid + "," + txfClass.CopypersonID + "," + txfClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + "" + billno + "\",\"picUrl\":\"@\",\"title\":\"" + txfClass.OperatorName + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + txfClass.FeeAmount + "¥ 发票: " + txfClass.BillCount + " 张\r\n申请日期: " + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n备注: " + txfClass.Notes + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请,消息通知失败(DD9004)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>入参:" + CsJson + "\r\n"); } CLFBX clfbxClass = new CLFBX(); clfbxClass = (CLFBX)JsonConvert.DeserializeObject(CsJson, typeof(CLFBX)); clfbxClass.Notes = Regex.Replace(clfbxClass.Notes, @"[\n\r]", "").Replace("\\", ""); if (clfbxClass.ExpeTravDetail.Length <= 0) { context.Response.Write("{\"errmsg\":\"费用明细不允许为空,请添加费用明细(DD7001)\",\"errcode\":1}"); return; } try { operatorGuid = clfbxClass.OperatorGuid; #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion if (clfbxClass.isRe == "1")//是否需要生产新的申请号 { #region 获取申请流水号 Sql = "select dbo.GetBillNo('DDTrvelReq','" + clfbxClass.JobNumber + "',getdate())"; obj = da.GetValue(Sql); billno = obj.ToString(); if (billno == "1") { billno = "CL" + clfbxClass.JobNumber + DateTime.Now.ToString("yyyyMMdd") + "0001"; Sql = "update BillNumber set MaxNum=1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq' and BillDate<>convert(varchar(20),GETDATE(),120)"; } else { Sql = "update BillNumber set MaxNum=MaxNum+1,BillDate=convert(varchar(20),GETDATE(),120) where BillGuid='DDTrvelReq'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新审批信息出错(DD6006)\",\"errcode\":1}"); return; } billno = billno + "_B"; #endregion } else { billno = clfbxClass.BillNo; } #region 保存信息 sqlList.Clear(); sqlTou.Clear(); sqlTou.Append("insert into ExpeTrav(BillNo,BillDate,Notes,OperatorGuid,Applpers,DDOperatorId,BearOrga,CostType,NoCountFee,SelAuditingGuid,CopyPerson,SelAuditingName,CopyPersonName,AppendixUrl,PictureUrl) values('") .Append(billno).Append("','") .Append(DateTime.Now.ToString("yyyy-MM-dd")).Append("','") .Append(clfbxClass.Notes).Append("','") .Append(clfbxClass.OperatorGuid).Append("','") .Append(clfbxClass.JobNumber).Append("','") .Append(clfbxClass.DDOperatorId).Append("','") .Append(clfbxClass.BearOrga).Append("','") .Append(clfbxClass.CostType).Append("','") .Append(clfbxClass.NoCountFee).Append("','") .Append(clfbxClass.SelAuditingGuid).Append("','") .Append(clfbxClass.CopyPerson).Append("','") .Append(clfbxClass.SelAuditingName).Append("','") .Append(clfbxClass.CopyPersonName).Append("','") .Append(clfbxClass.AppendixUrl).Append("','") .Append(clfbxClass.PictureUrl).Append("')"); sqlList.Add(sqlTou.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insertTou:" + sqlTou.ToString() + "\r\n"); } sqlTou.Clear(); sqlTou.Append("insert into ExpetravDetail(TripNo,BillNo,Guid,DepaDate,RetuDate,DepaCity,DestCity,DepaCity1,DestCity1,CustCode,DetailNo,AlloDay,OffDay,AlloPric,AlloAmount,OtherFee,TranMode,TranCount,TranAmount,GasAmount,HsrAmount,AccoCount,AccoAmount,CityTrafCount,CityTraAmont,TotalAmount) values('"); for (int i = 0; i < clfbxClass.ExpeTravDetail.Length; i++) { AccoCount = "0"; // 住宿票张数 AccoAmount = "0"; // 住宿金额 CityTrafCount = "0"; // 市内交通票张数 CityTraAmount = "0"; // 市内交通金额 oneSumAmount = 0; //第一行的和 SumMony = SumMony + Double.Parse(clfbxClass.ExpeTravDetail[i].TotalAmount); sqlTiPro.Clear(); detailNo = detailNo + 1; TripNo = 1; sqlTiPro.Append(sqlTou.ToString()).Append(i + 1).Append("','") .Append(billno).Append("',newid(),'") .Append(clfbxClass.ExpeTravDetail[i].DepaDate).Append("','") .Append(clfbxClass.ExpeTravDetail[i].RetuDate).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DepaCity3).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DestCity3).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DepaCity1).Append("','") .Append(clfbxClass.ExpeTravDetail[i].DestCity1).Append("','") .Append(clfbxClass.ExpeTravDetail[i].CustCode).Append("','"); for (int j = 0; j < clfbxClass.ExpeTravDetail[i].PList.Length; j++) { if (j == 0) { sqlTi.Clear(); sqlTi.Append(sqlTiPro.ToString()).Append(detailNo) .Append("','").Append(clfbxClass.ExpeTravDetail[i].AlloDay) .Append("','").Append(clfbxClass.ExpeTravDetail[i].OffDay) .Append("','").Append(clfbxClass.ExpeTravDetail[i].AlloPric) .Append("','").Append(clfbxClass.ExpeTravDetail[i].AlloAmount) .Append("','").Append(clfbxClass.ExpeTravDetail[i].OtherFee); oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].AlloAmount) + Double.Parse(clfbxClass.ExpeTravDetail[i].OtherFee); } if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "火车票" || clfbxClass.ExpeTravDetail[i].PList[j].FType == "飞机票" || clfbxClass.ExpeTravDetail[i].PList[j].FType == "汽车票" || clfbxClass.ExpeTravDetail[i].PList[j].FType == "轮船票") { if (TripNo == 1) { sqlTi.Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0"); oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].Amount); detailNo = detailNo + 1; TripNo = TripNo + 1; } else { sqlTi2.Clear(); sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType.Replace("票", "")) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Amount) .Append("','0','0','0','0','0','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].SumAmount) .Append("')"); sqlList.Add(sqlTi2.ToString()); detailNo = detailNo + 1; TripNo = TripNo + 1; ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insertTi:" + sqlTi2.ToString() + "\r\n"); } } else if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "自驾") { if (TripNo == 1) { sqlTi.Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].GasAmount) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].HsrAmount); oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].SumAmount); detailNo = detailNo + 1; TripNo = TripNo + 1; } else { sqlTi2.Clear(); sqlTi2.Append(sqlTiPro.ToString()).Append(detailNo).Append("','0','0','0','0','0") .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].FType) .Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].Count) .Append("','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].GasAmount).Append("','").Append(clfbxClass.ExpeTravDetail[i].PList[j].HsrAmount).Append("','0','0','0','0','").Append(clfbxClass.ExpeTravDetail[i].PList[j].SumAmount) .Append("')"); sqlList.Add(sqlTi2.ToString()); detailNo = detailNo + 1; TripNo = TripNo + 1; ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insertTi:" + sqlTi2.ToString() + "\r\n"); } } else if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "住宿票") { AccoCount = clfbxClass.ExpeTravDetail[i].PList[j].Count; AccoAmount = clfbxClass.ExpeTravDetail[i].PList[j].Amount; oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].Amount); } else if (clfbxClass.ExpeTravDetail[i].PList[j].FType == "市内交通票") { CityTrafCount = clfbxClass.ExpeTravDetail[i].PList[j].Count; CityTraAmount = clfbxClass.ExpeTravDetail[i].PList[j].Amount; oneSumAmount = oneSumAmount + Double.Parse(clfbxClass.ExpeTravDetail[i].PList[j].Amount); } } sqlTi.Append("','").Append(AccoCount) .Append("','").Append(AccoAmount) .Append("','").Append(CityTrafCount) .Append("','").Append(CityTraAmount) .Append("','").Append(oneSumAmount).Append("')"); sqlList.Add(sqlTi.ToString()); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nExpeTravReq=>insert:" + sqlTi.ToString() + "\r\n"); } } obj = da.ExecSql(sqlList); if (obj == null) { context.Response.Write("{\"errmsg\":\"保存出差申请信息出错(DD6002)\",\"errcode\":1}"); return; } #endregion #region 调用提交存储过程 if (!sqlPro()) { aList.Clear(); Sql = "delete from ExpeTrav where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from ExpetravDetail where BillNo='" + billno + "'"; aList.Add(Sql); Sql = "delete from CUSTIMPLLOG where SourceBill='" + billno + "'"; aList.Add(Sql); obj = da.ExecSql(aList); if (obj == null) { context.Response.Write("{\"errmsg\":\"删除提交信息出错(DD6006)\",\"errcode\":1}"); return; } context.Response.Write("{\"errmsg\":\"" + ProResult + "(DD9003)\",\"errcode\":1}"); return; } #endregion #region 差旅费报销 申请 发送工作通知消息 url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + clfbxClass.SelAuditingGuid + "," + clfbxClass.CopyPerson + "," + clfbxClass.DDOperatorId + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + ddUrl + "/clfui/shenpi/index.html?billno=" + billno + "\",\"picUrl\":\"@\",\"title\":\"" + clfbxClass.OperatorName + "的【差旅费】报销申请\",\"text\":\"金额: " + SumMony + " ¥\r\n行程: " + clfbxClass.ExpeTravDetail[0].DepaCity1 + " - " + clfbxClass.ExpeTravDetail[0].DestCity1 + "\r\n申请日期: " + System.DateTime.Now.ToString("yyyy-MM-dd") + "\"}}}"; FhJson = ToolsClass.ApiFun("POST", url, CsJson); XXTZ xxtzClass = new XXTZ(); xxtzClass = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的差旅费报销申请消息通知失败(DD6004)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD0005)\",\"errcode\":1}"); context.Response.End(); } }
string ddUrl = ""; //钉钉前端地址 public void ProcessRequest(HttpContext context) { //判断客户端请求是否为post方法 if (context.Request.HttpMethod.ToUpper() != "POST") { context.Response.Write("{\"errmsg\":\"请求方式不允许,请使用POST方式(DD0001)\",\"errcode\":1}"); return; } //数据库链接 connectionString = ToolsClass.GetConfig("DataOnLine"); //sqlServer da = new DbHelper.SqlHelper("SqlServer", connectionString); //获取请求json using (var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8)) { CsJson = reader.ReadToEnd(); } if (CsJson == "") { context.Response.Write("{\"errmsg\":\"报文格式错误(DD0003)\",\"errcode\":1}"); return; } CsJson = Regex.Replace(CsJson, @"[\n\r]", "").Replace(@"\n", ""); //#微应用ID:agentId #企业ID:corpId #应用的唯一标识:appKey #应用的密钥:appSecret AppWyy = ToolsClass.GetConfig("AppWyy"); ScList = AppWyy.Split('$'); agentId = ScList[0].ToString(); corpId = ScList[1].ToString(); appKey = ScList[2].ToString(); appSecret = ScList[3].ToString(); isWrite = ToolsClass.GetConfig("isWrite"); ddUrl = ToolsClass.GetConfig("ddUrl"); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nSendMsg=>入参:" + CsJson + "\r\n"); } //前端传入数据 TravelApproval traApprClass = new TravelApproval(); traApprClass = (TravelApproval)JsonConvert.DeserializeObject(CsJson, typeof(TravelApproval)); try { #region 设置消息跳转链接地址 if (traApprClass.FeeType == "01") { //市内交通费; typeName = "交通费"; typeUrl = ddUrl + "/jtfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "02") { //通讯费 typeName = "通讯费"; typeUrl = ddUrl + "/txfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "03") { //车辆费 typeName = "车辆费"; typeUrl = ddUrl + "/clui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "04") { //房租费 typeName = "房租费"; typeUrl = ddUrl + "/fzfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "05") { //水费 typeName = "水费"; typeUrl = ddUrl + "/sfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "06") { //电费 typeName = "电费"; typeUrl = ddUrl + "/dfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "11") { //出差 typeName = "出差"; typeUrl = ddUrl + "/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "12") { //差旅费 typeName = "差旅费"; typeUrl = ddUrl + "/clfui/shenpi/index.html?billno="; } else if (traApprClass.FeeType == "00") { //招待费 typeName = "招待费"; typeUrl = ddUrl + "/zdfui/shenpi/index.html?billno="; } else { context.Response.Write("{\"errmsg\":\"提交的申请类型不存在(DD9001)\",\"errcode\":1}"); return; } #endregion #region 获取access_token url = "https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret; FhJson = ToolsClass.ApiFun("GET", url, ""); TokenClass tokenClass = new TokenClass(); tokenClass = (TokenClass)JsonConvert.DeserializeObject(FhJson, typeof(TokenClass)); access_token = tokenClass.access_token; errcode = tokenClass.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"获取ACCESS_TOKEN报错(DD0004)\",\"errcode\":1}"); return; } #endregion #region 获取通知信息字段 //出差 if (traApprClass.FeeType == "11") { Sql = "select a.TravelReason,convert(varchar(20),min(b.StartDate),23) StartDate,convert(varchar(20),max(EndDate),23) EndDate from TravelReq a left join TravelReqDetail b on a.billno=b.billno where a.billno='" + traApprClass.BillNo + "' group by a.billno,a.TravelReason"; } //差旅费报销申请 else if (traApprClass.FeeType == "12") { Sql = "select top 1 A.DepaCity1 DepaCity,A.DestCity1 DestCity,b.TranAmount,convert(varchar(20),c.BillDate,23) BillDate from ExpeTravDetail A left join (select billno,sum(TotalAmount) TranAmount from ExpeTravDetail group by billno) b on a.billno=b.billno left join ExpeTrav c on a.BillNo=c.BillNo where a.BillNo = '" + traApprClass.BillNo + "' order by a.depadate"; } //招待费 else if (traApprClass.FeeType == "00") { Sql = "select FeeAmount,BillCount,convert(varchar(20),ReferDate,23) BillDate,Notes from EXPEENTEMENT where billno='" + traApprClass.BillNo + "'"; } //其他费用 else { Sql = "select FeeAmount,BillCount,convert(varchar(20),ReferDate,23) BillDate,Notes from EXPEOTHER where billno='" + traApprClass.BillNo + "'"; } obj = da.GetDataTable(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"用户不存在(DD9002)\",\"errcode\":1}"); return; } dt = obj as DataTable; if (dt.Rows.Count == 0) { context.Response.Write("{\"errmsg\":\"申请信息不存在(DD9003)\",\"errcode\":1}"); return; } #endregion #region 发送工作通知消息 //出差 if (traApprClass.FeeType == "11") { CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.CopyPerson + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"" + traApprClass.OperatorName + "的【" + typeName + "】申请\",\"text\":\"出发日期: " + dt.Rows[0]["StartDate"].ToString() + "\r\n返程日期: " + dt.Rows[0]["EndDate"].ToString() + "\r\n事由: " + dt.Rows[0]["TravelReason"].ToString() + "\"}}}"; } //差旅费报销申请 else if (traApprClass.FeeType == "12") { CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.CopyPerson + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"" + traApprClass.OperatorName + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + dt.Rows[0]["TranAmount"].ToString() + " ¥\r\n行程: " + dt.Rows[0]["DepaCity"].ToString() + " - " + dt.Rows[0]["DestCity"].ToString() + "\r\n申请日期: " + dt.Rows[0]["BillDate"].ToString() + "\"}}}"; } //其他费用 else { CsJson = "{\"agent_id\":\"" + agentId + "\",\"userid_list\":\"" + traApprClass.CopyPerson + "\",\"msg\":{\"msgtype\":\"link\",\"link\":{\"messageUrl\":\"" + typeUrl + traApprClass.BillNo + "\",\"picUrl\":\"@\",\"title\":\"" + traApprClass.OperatorName + "的【" + typeName + "】报销申请\",\"text\":\"金额: " + dt.Rows[0]["FeeAmount"].ToString() + "¥ 发票: " + dt.Rows[0]["BillCount"].ToString() + " 张\r\n申请日期: " + dt.Rows[0]["BillDate"].ToString() + "\r\n备注: " + dt.Rows[0]["Notes"].ToString() + "\"}}}"; } url = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + access_token; FhJson = ToolsClass.ApiFun("POST", url, CsJson); if (isWrite == "1") { ToolsClass.TxtLog("DDLog", "\r\nSendMsg=>CsJson:" + CsJson + "FhJson\r\n:" + FhJson); } XXTZ xxtzClass2 = new XXTZ(); xxtzClass2 = (XXTZ)JsonConvert.DeserializeObject(FhJson, typeof(XXTZ)); errcode = xxtzClass2.errcode; if (errcode != 0) { context.Response.Write("{\"errmsg\":\"您的报销申请消息通知失败(DD9004)\",\"errcode\":1}"); return; } #endregion #region 更新 将转发人拼接在抄送人字段后面 //出差 if (traApprClass.FeeType == "11") { Sql = "update TravelReq set CopyPerson=(case when isnull(CopyPerson,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPerson+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } //差旅费报销申请 else if (traApprClass.FeeType == "12") { Sql = "update ExpeTrav set CopyPerson=(case when isnull(CopyPerson,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPerson+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } //招待费 else if (traApprClass.FeeType == "00") { Sql = "update EXPEENTEMENT set CopyPersonID=(case when isnull(CopyPersonID,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPersonID+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } //其他费用 else { Sql = "update EXPEOTHER set CopyPersonID=(case when isnull(CopyPersonID,' ')=' ' then '" + traApprClass.CopyPerson + "' else CopyPersonID+','+'" + traApprClass.CopyPerson + "' end) where billno='" + traApprClass.BillNo + "'"; } obj = da.ExecSql(Sql); if (obj == null) { context.Response.Write("{\"errmsg\":\"更新抄送人信息出错(DD9005)\",\"errcode\":1}"); return; } #endregion context.Response.Write("{\"errmsg\":\"ok\",\"errcode\":0}"); return; } catch (Exception ex) { context.Response.Write("{\"errmsg\":\"提交的信息有误(DD9006)\",\"errcode\":1}"); context.Response.End(); } }