Example #1
0
        /// <summary>
        /// 处理添加/修改学员信息操作表
        /// </summary>
        internal static void Deal0()
        {
            BasicClass basic = new BasicClass();

            while (true)
            {
                //从添加/修改学员操作表中获取未处理的记录
                DataTable dt_student = basic.GetStudentInfo();
                if (dt_student != null && dt_student.Rows.Count > 0)
                {
                    //循环遍历
                    for (int i = 0; i < dt_student.Rows.Count; i++)
                    {
                        int    id              = Convert.ToInt32(dt_student.Rows[i]["Id"]);
                        string studentNo       = dt_student.Rows[i].IsNull("StudentNo") ? string.Empty : dt_student.Rows[i]["StudentNo"].ToString();
                        string realName        = dt_student.Rows[i].IsNull("RealName") ? string.Empty : dt_student.Rows[i]["RealName"].ToString();
                        int    sex             = dt_student.Rows[i].IsNull("Sex") ? 0 : Convert.ToInt32(dt_student.Rows[i]["Sex"]);
                        string phone           = dt_student.Rows[i].IsNull("Phone") ? string.Empty : dt_student.Rows[i]["Phone"].ToString();
                        string email           = dt_student.Rows[i].IsNull("Email") ? string.Empty : dt_student.Rows[i]["Email"].ToString();
                        string nation          = dt_student.Rows[i].IsNull("Nation") ? string.Empty : dt_student.Rows[i]["Nation"].ToString();
                        int    certificateType = dt_student.Rows[i].IsNull("CertificateType") ? -1 : Convert.ToInt32(dt_student.Rows[i]["CertificateType"]);
                        string certificateCode = dt_student.Rows[i].IsNull("CertificateCode") ? string.Empty : dt_student.Rows[i]["CertificateCode"].ToString();
                        string url             = dt_student.Rows[i].IsNull("Url") ? string.Empty : dt_student.Rows[i]["Url"].ToString();
                        int    type            = dt_student.Rows[i].IsNull("Type") ? -1 : Convert.ToInt32(dt_student.Rows[i]["Type"]);
                        int    sendTimes       = dt_student.Rows[i].IsNull("SendTimes") ? 0 : Convert.ToInt32(dt_student.Rows[i]["SendTimes"]);
                        string projectCode     = dt_student.Rows[i].IsNull("ProjectCode") ? string.Empty : dt_student.Rows[i]["ProjectCode"].ToString();
                        int    userId          = dt_student.Rows[i].IsNull("UserId") ? 0 : Convert.ToInt32(dt_student.Rows[i]["UserId"]);

                        //准备接口所需要的参数
                        string cards = string.Empty;
                        if (certificateType >= 0 && !string.IsNullOrEmpty(certificateCode))
                        {
                            cards = "{\"CertificateType\":\"" + certificateType.ToString() + "\",\"CertificateNum\":\"" + certificateCode + "\"}";
                        }

                        string studentJsonStr = string.Empty;
                        if (type == 0)
                        {
                            //添加
                            studentJsonStr = "{\"RealName\":\"" + realName + "\",\"Sex\":\"" + sex.ToString() + "\",\"Phone\":\"" + phone + "\",\"Email\":\"" + email + "\",\"Nation\":\"" + nation + "\",\"Certificates\":[" + cards + "]}";
                        }
                        else if (type == 1)
                        {
                            //修改
                            studentJsonStr = "{\"StudentNo\":\"" + studentNo + "\",\"RealName\":\"" + realName + "\",\"Sex\":\"" + sex.ToString() + "\",\"Phone\":\"" + phone + "\",\"Email\":\"" + email + "\",\"Nation\":\"" + nation + "\",\"Certificates\":[" + cards + "]}";
                        }
                        string aeskey    = string.Empty;
                        string aesiv     = string.Empty;
                        string aesString = basic.GetAesKeyByUserId(userId);
                        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(studentJsonStr, aeskey, aesiv);
                        }
                        string result = basic.PostData(url, projectCode, encryption);
                        if (!string.IsNullOrEmpty(result))
                        {
                            if (type == 0)
                            {
                                var addResult = basic.JsonStr2Obj <AddResult>(result);
                                if (addResult != null)
                                {
                                    basic.UpdateStudentStatus(id, addResult.ReturnValue.Trim(), addResult.Code, addResult.Message);
                                    if (addResult.Code.Trim() == "0")
                                    {
                                        //添加学员成功
                                        //更新学员表studentno
                                        basic.UpdateStudentNo(userId, addResult.ReturnValue.Trim());
                                        //更新一下该学员支付表中的学号
                                        basic.UpdatePayStudentNo(userId, addResult.ReturnValue.Trim(), projectCode);
                                        //向学员报名操作表中插入一条未处理的数据
                                        basic.InsertIntoReformSignUp(projectCode, addResult.ReturnValue.Trim(), ConfigurationManager.AppSettings["ReformInterface"].ToString() + "/SignUp");
                                    }
                                }
                                else
                                {
                                    //添加失败
                                    //如果累计提交次数达到3次,将操作表中的状态修改为处理失败;如果未达到3次将处理次数加1
                                    basic.UpdateStudentSendTimes(id, string.Empty, string.Empty, sendTimes);
                                }
                            }
                            else if (type == 1)
                            {
                                var modifyResult = basic.JsonStr2Obj <ModifyResult>(result);
                                if (modifyResult != null)
                                {
                                    //修改成功
                                    basic.UpdateStudentStatus(id, studentNo, modifyResult.Code, modifyResult.Message);
                                }
                                else
                                {
                                    //修改失败
                                    basic.UpdateStudentSendTimes(id, string.Empty, string.Empty, sendTimes);
                                }
                            }
                        }
                        else
                        {
                            basic.UpdateStudentSendTimes(id, string.Empty, string.Empty, sendTimes);
                        }
                    }
                }

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