Beispiel #1
0
        /// <summary>
        /// 处理学员支付操作表
        /// </summary>
        internal static void Deal2()
        {
            BasicClass basic = new BasicClass();

            while (true)
            {
                //获取支付操作表中项目编号 ProjectCode
                DataTable dt_project = basic.GetPayProjectCode();
                if (dt_project != null && dt_project.Rows.Count > 0)
                {
                    for (int i = 0; i < dt_project.Rows.Count; i++)
                    {
                        string projectCode = dt_project.Rows[i].IsNull("ProjectCode") ? string.Empty : dt_project.Rows[i]["ProjectCode"].ToString();
                        if (!string.IsNullOrEmpty(projectCode))
                        {
                            //获取某个项目下的支付记录
                            DataTable dt_PayRecords = basic.GetPayRecords(projectCode);
                            if (dt_PayRecords != null && dt_PayRecords.Rows.Count > 0)
                            {
                                //拼接支付记录Json
                                long          timeStamp = basic.GetTimeStamp(DateTime.Now);
                                string        payJson   = string.Empty;
                                StringBuilder sb        = new StringBuilder();
                                for (int j = 0; j < dt_PayRecords.Rows.Count; j++)
                                {
                                    string studentNo = dt_PayRecords.Rows[j].IsNull("StudentNo") ? string.Empty : dt_PayRecords.Rows[j]["StudentNo"].ToString();
                                    string payAmount = dt_PayRecords.Rows[j].IsNull("PayAmount") ? string.Empty : dt_PayRecords.Rows[j]["PayAmount"].ToString();
                                    string payTime   = dt_PayRecords.Rows[j].IsNull("PayTime") ? string.Empty : basic.GetTimeStamp(Convert.ToDateTime(dt_PayRecords.Rows[j]["PayTime"])).ToString();
                                    string payDesc   = dt_PayRecords.Rows[j].IsNull("PayDesc") ? string.Empty : dt_PayRecords.Rows[j]["PayDesc"].ToString();
                                    int    classId   = dt_PayRecords.Rows[j].IsNull("ClassId") ? 0 : Convert.ToInt32(dt_PayRecords.Rows[j]["ClassId"]);
                                    if (!string.IsNullOrEmpty(studentNo) && !string.IsNullOrEmpty(payAmount) && !string.IsNullOrEmpty(payTime) && !string.IsNullOrEmpty(payDesc))
                                    {
                                        sb.Append("{\"StudentNo\":\"" + studentNo + "\",\"PayAmount\":\"" + payAmount + "\",\"PayTime\":\"" + payTime + "\",\"PayDesc\":\"" + payDesc + "\",\"ClassId\":\"" + classId.ToString() + "\"},");
                                    }
                                }
                                if (sb.Length > 0)
                                {
                                    payJson = sb.Remove(sb.Length - 1, 1).ToString();
                                }
                                string jsonStr = "{\"TimeStamp\":\"" + timeStamp.ToString() + "\",\"Records\":[" + payJson + "]}";

                                string aeskey    = string.Empty;
                                string aesiv     = string.Empty;
                                string aesString = basic.GetAesKeyByProjectCode(projectCode);
                                if (aesString.Contains(","))
                                {
                                    aeskey = aesString.Split(',')[0];
                                    aesiv  = aesString.Split(',')[1];
                                }
                                string encryption = string.Empty;
                                if (!string.IsNullOrEmpty(aeskey) && !string.IsNullOrEmpty(aesiv))
                                {
                                    encryption = basic.Encrypt(jsonStr, aeskey, aesiv);
                                }

                                //调用接口
                                string result = basic.PostData(ConfigurationManager.AppSettings["ReformInterface"].ToString() + "/PaySubmit", projectCode, encryption);
                                if (!string.IsNullOrEmpty(result))
                                {
                                    var submitRecordResult = basic.JsonStr2Obj <SubmitRecordResult>(result);
                                    if (submitRecordResult != null)
                                    {
                                        if (submitRecordResult.Success.Count > 0)
                                        {
                                            //提交成功的记录
                                            var    sucList    = submitRecordResult.Success;
                                            int    sucNumber  = 0;
                                            string sucMessage = string.Empty;
                                            foreach (var item in sucList)
                                            {
                                                sucNumber  = item.number;
                                                sucMessage = item.msg;
                                                if (sucNumber >= 0)
                                                {
                                                    basic.UpdatePayRecordStatus(Convert.ToInt32(dt_PayRecords.Rows[sucNumber]["Id"]), sucMessage, Convert.ToInt32(dt_PayRecords.Rows[sucNumber].IsNull("SendTimes") ? 0 : dt_PayRecords.Rows[sucNumber]["SendTimes"]));
                                                }
                                            }
                                        }
                                        if (submitRecordResult.Failed.Count > 0)
                                        {
                                            //提交失败的记录
                                            var    failList    = submitRecordResult.Failed;
                                            int    failNumber  = 0;
                                            string failMessage = string.Empty;
                                            foreach (var item in failList)
                                            {
                                                failNumber  = item.number;
                                                failMessage = item.msg;
                                                if (failNumber >= 0)
                                                {
                                                    basic.UpdatePayRecordStatus(Convert.ToInt32(dt_PayRecords.Rows[failNumber]["Id"]), failMessage, Convert.ToInt32(dt_PayRecords.Rows[failNumber].IsNull("SendTimes") ? 0 : dt_PayRecords.Rows[failNumber]["SendTimes"]));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //休眠一小时
                Thread.Sleep(1000 * 60 * Convert.ToInt32(ConfigurationManager.AppSettings["deal2_sleep"]));
            }
        }