Пример #1
0
        /// <summary>
        /// 处理学员报名项目操作表
        /// </summary>
        internal static void Deal1()
        {
            BasicClass basic = new BasicClass();

            while (true)
            {
                //从报名项目操作表中取出还没有处理的记录
                DataTable dt_SignUp = basic.GetSignUpInfo();
                if (dt_SignUp != null && dt_SignUp.Rows.Count > 0)
                {
                    for (int i = 0; i < dt_SignUp.Rows.Count; i++)
                    {
                        int    id          = Convert.ToInt32(dt_SignUp.Rows[i]["Id"]);
                        string studentNo   = dt_SignUp.Rows[i].IsNull("StudentNo") ? string.Empty : dt_SignUp.Rows[i]["StudentNo"].ToString();
                        string projectCode = dt_SignUp.Rows[i].IsNull("ProjectCode") ? string.Empty : dt_SignUp.Rows[i]["ProjectCode"].ToString();
                        string url         = dt_SignUp.Rows[i].IsNull("Url") ? string.Empty : dt_SignUp.Rows[i]["Url"].ToString();
                        int    sendTimes   = dt_SignUp.Rows[i].IsNull("SendTimes") ? 0 : Convert.ToInt32(dt_SignUp.Rows[i]["SendTimes"]);
                        int    classId     = dt_SignUp.Rows[i].IsNull("ClassId") ? 0 : Convert.ToInt32(dt_SignUp.Rows[i]["ClassId"]);
                        //准备接口所需参数
                        long   timestamp     = basic.GetTimeStamp(DateTime.Now);
                        string signUpJsonStr = "{\"TimeStamp\":\"" + timestamp.ToString() + "\",\"StudentNo\":\"" + studentNo + "\",\"ClassId\":\"" + classId.ToString() + "\"}";

                        string aeskey    = string.Empty;
                        string aesiv     = string.Empty;
                        string aesString = basic.GetAesKeyByStudentNo(studentNo);
                        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(signUpJsonStr, aeskey, aesiv);
                        }
                        //调用接口
                        string result = basic.PostData(url, projectCode, encryption);
                        if (!string.IsNullOrEmpty(result))
                        {
                            var signUpResult = basic.JsonStr2Obj <SignUpResult>(result);
                            if (signUpResult != null)
                            {
                                //报名成功
                                //更新操作表记录的状态
                                basic.UpdateSignUpStatus(id, signUpResult.Code, signUpResult.Message, signUpResult.ReturnValue.Trim());
                                //如果审核通过则更新报名表Res_CourseEnter记录的审核状态
                                if (signUpResult.ReturnValue.Trim() == "1")
                                {
                                    basic.UpdateCourseEnterStatus(projectCode, studentNo);
                                }
                            }
                            else
                            {
                                //报名失败
                                //更新操作表记录的sendTimes
                                basic.UpdateSignUpSendTimes(id, sendTimes, string.Empty, string.Empty);
                            }
                        }
                        else
                        {
                            basic.UpdateSignUpSendTimes(id, sendTimes, string.Empty, string.Empty);
                        }
                    }
                }


                //休眠十分钟
                Thread.Sleep(1000 * 60 * Convert.ToInt32(ConfigurationManager.AppSettings["deal1_sleep"]));
            }
        }