Commit 94d5dbd2 authored by 黄奎's avatar 黄奎

页面修改

parent 47041ac9
using EduSpider.Spiders.ClassInRule; using EduSpider.Spiders.ClassInRule;
using EduSpider.Utility.Plugin; using EduSpider.Utility.Plugin;
using System;
using System.Threading;
namespace TicketSpider.Spiders.ClassInRule namespace TicketSpider.Spiders.ClassInRule
{ {
......
...@@ -18,10 +18,14 @@ namespace EduSpider.Spiders.ClassInRule ...@@ -18,10 +18,14 @@ namespace EduSpider.Spiders.ClassInRule
private static readonly IStudentRepository courseRepository = new StudentRepository(); private static readonly IStudentRepository courseRepository = new StudentRepository();
/// <summary>
/// 获取学生数据
/// </summary>
/// <param name="cookie"></param>
public static async void RunAsync(string cookie) public static async void RunAsync(string cookie)
{ {
var request = Utility.HttpHelper.GenerateHttp(cookie); var request = Utility.HttpHelper.GenerateHttp(cookie);
int pageIndex = 1, pageCount = 1, pageSize=500; int pageIndex = 1, pageCount = 1, pageSize = 500;
#region 获取最大学生ID #region 获取最大学生ID
//更新账户 //更新账户
...@@ -31,78 +35,81 @@ namespace EduSpider.Spiders.ClassInRule ...@@ -31,78 +35,81 @@ namespace EduSpider.Spiders.ClassInRule
List<rb_account_hk> accountList = new(); List<rb_account_hk> accountList = new();
#endregion #endregion
while (pageIndex <= pageCount) while (pageIndex <= pageCount)
{ {
InfoHelper.WriteLine($"正在查询第{pageIndex}-{pageSize}页学员信息"); InfoHelper.WriteLine($"正在查询第{pageIndex}-{pageSize}页学员信息");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"正在查询第{pageIndex}-{pageSize}页学员信息"); VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"正在查询第{pageIndex}-{pageSize}页学员信息");
var paramStr = $"page={pageIndex}&perpage={pageSize}&isdel=0"; var paramStr = $"page={pageIndex}&perpage={pageSize}&isdel=0";
var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded"); var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await request.PostAsync("https://console.eeo.cn/saasajax/student.ajax.php?action=getSchoolStudentListByPage", content); try
var resultStr = response.Content.ReadAsStringAsync().Result ?? string.Empty;
var result = resultStr.TryToJObject();
if (result.flag)
{ {
var data = (result.val.ContainsKey("data") ? result.val["data"] : new JObject()) as JObject; var response = await request.PostAsync("https://console.eeo.cn/saasajax/student.ajax.php?action=getSchoolStudentListByPage", content);
if (data.ContainsKey("totalStudentNum")) { var resultStr = response.Content.ReadAsStringAsync().Result ?? string.Empty;
var result = resultStr.TryToJObject();
#region 更新PageCount if (result.flag)
{
if (pageIndex == 1) var data = (result.val.ContainsKey("data") ? result.val["data"] : new JObject()) as JObject;
if (data.ContainsKey("totalStudentNum"))
{ {
pageCount = (int)Math.Ceiling(data.GetDecimal("totalStudentNum") / pageSize); #region 更新PageCount
} if (pageIndex == 1)
#endregion
#region 组装实体
var stus = new List<rb_student_hk>();
var stuArray = (data["studentList"] as JArray);
foreach (JObject x in stuArray)
{
stus.Add(new rb_student_hk()
{ {
AddTime = ConvertHelper.UnixToDateTime(x.GetString("addTime")), pageCount = (int)Math.Ceiling(data.GetDecimal("totalStudentNum") / pageSize);
StudentAccount=x.GetString("studentAccount"), }
Isdel= x.GetInt("isdel",0), #endregion
IsGroup = x.GetInt("isGroup", 0),
StudId = x.GetInt("studId", 0),
Progress = x.GetString("progress"),
PublicResourceStatus = x.GetInt("publicResourceStatus", 0),
ServeState = x.GetInt("serveState", 0),
StudentName = x.GetString("studentName"),
StudentUid = x.GetInt("studentUid", 0),
Stuno = x.GetString("stuno"),
});
}
courseRepository.BatchSetStudent(stus);
InfoHelper.WriteLine($"已导入第{pageIndex}-{pageSize}页学员信息");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"已导入第{pageIndex}-{pageSize}页学员信息");
#endregion
#region 写入账号 #region 组装实体
if (stus.Any(x => x.StudId > MaxStuId)) { var stus = new List<rb_student_hk>();
foreach (var item in stus.Where(x => x.StudId > MaxStuId)) var stuArray = (data["studentList"] as JArray);
foreach (JObject x in stuArray)
{ {
accountList.Add(new rb_account_hk() stus.Add(new rb_student_hk()
{ {
UniqueId = 0, AddTime = ConvertHelper.UnixToDateTime(x.GetString("addTime")),
Id = item.StudId, StudentAccount = x.GetString("studentAccount"),
Account = item.StudentAccount, Isdel = x.GetInt("isdel", 0),
AccountId = item.StudentUid, IsGroup = x.GetInt("isGroup", 0),
AccountType = Utility.Enum.AccountTypeEnum.Student, StudId = x.GetInt("studId", 0),
OpenId = "", Progress = x.GetString("progress"),
Password = DESHepler.Encrypt(item.StudentAccount[^6..]), PublicResourceStatus = x.GetInt("publicResourceStatus", 0),
Status = 0, ServeState = x.GetInt("serveState", 0),
UnionId = "" StudentName = x.GetString("studentName"),
StudentUid = x.GetInt("studentUid", 0),
Stuno = x.GetString("stuno"),
}); });
} }
courseRepository.BatchSetStudent(stus);
InfoHelper.WriteLine($"已导入第{pageIndex}-{pageSize}页学员信息");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"已导入第{pageIndex}-{pageSize}页学员信息");
#endregion
#region 写入账号
if (stus.Any(x => x.StudId > MaxStuId))
{
foreach (var item in stus.Where(x => x.StudId > MaxStuId))
{
accountList.Add(new rb_account_hk()
{
UniqueId = 0,
Id = item.StudId,
Account = item.StudentAccount,
AccountId = item.StudentUid,
AccountType = Utility.Enum.AccountTypeEnum.Student,
OpenId = "",
Password = DESHepler.Encrypt(item.StudentAccount[^6..]),
Status = 0,
UnionId = ""
});
}
}
#endregion
} }
#endregion
} }
} }
catch (Exception ex)
{
VTX.FW.Helper.LogHelper.WriteError("StudentManager_RunAsync", ex: ex);
}
pageIndex++; pageIndex++;
} }
...@@ -115,8 +122,6 @@ namespace EduSpider.Spiders.ClassInRule ...@@ -115,8 +122,6 @@ namespace EduSpider.Spiders.ClassInRule
InfoHelper.WriteLine("学员同步完成"); InfoHelper.WriteLine("学员同步完成");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"学员同步完成"); VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"学员同步完成");
} }
} }
} }
...@@ -29,39 +29,45 @@ namespace EduSpider.Spiders.ClassInRule ...@@ -29,39 +29,45 @@ namespace EduSpider.Spiders.ClassInRule
{ {
string paramStr = string.Format("page={0}&perpage={1}", pageIndex, perpage); string paramStr = string.Format("page={0}&perpage={1}", pageIndex, perpage);
var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded"); var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await request.PostAsync("https://console.eeo.cn/saasajax/teacher.ajax.php?action=getSchoolTeacherFullList", content); try
var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(result))
{ {
VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}"); var response = await request.PostAsync("https://console.eeo.cn/saasajax/teacher.ajax.php?action=getSchoolTeacherFullList", content);
JObject rootObj = JObject.Parse(result); var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(rootObj.GetString("data"))) if (!string.IsNullOrWhiteSpace(result))
{ {
JObject dataObj = JObject.Parse(rootObj.GetString("data")); VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}");
var totalNum = dataObj.GetInt("totalNum"); JObject rootObj = JObject.Parse(result);
string rlist = dataObj.GetString("list"); if (!string.IsNullOrWhiteSpace(rootObj.GetString("data")))
if (pageIndex == 1)
{ {
if (totalNum > perpage) JObject dataObj = JObject.Parse(rootObj.GetString("data"));
var totalNum = dataObj.GetInt("totalNum");
string rlist = dataObj.GetString("list");
if (pageIndex == 1)
{ {
if (totalNum % perpage == 0) if (totalNum > perpage)
{ {
pageCount = totalNum / perpage; if (totalNum % perpage == 0)
} {
else pageCount = totalNum / perpage;
{ }
pageCount = (totalNum / perpage) + 1; else
{
pageCount = (totalNum / perpage) + 1;
}
} }
} }
list.AddRange(ParseJson(rlist));
} }
}
list.AddRange(ParseJson(rlist)); else
{
Console.WriteLine("result", result);
VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}");
} }
} }
else catch (Exception ex)
{ {
Console.WriteLine("result", result); VTX.FW.Helper.LogHelper.WriteError("RunTeacher",ex:ex);
VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}");
} }
if (pageIndex == pageCount) if (pageIndex == pageCount)
{ {
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TicketSpider.Spiders
{
public interface ICookiesManager
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment