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

页面修改

parent 47041ac9
using EduSpider.Spiders.ClassInRule;
using EduSpider.Utility.Plugin;
using System;
using System.Threading;
namespace TicketSpider.Spiders.ClassInRule
{
......
......@@ -18,10 +18,14 @@ namespace EduSpider.Spiders.ClassInRule
private static readonly IStudentRepository courseRepository = new StudentRepository();
/// <summary>
/// 获取学生数据
/// </summary>
/// <param name="cookie"></param>
public static async void RunAsync(string cookie)
{
var request = Utility.HttpHelper.GenerateHttp(cookie);
int pageIndex = 1, pageCount = 1, pageSize=500;
int pageIndex = 1, pageCount = 1, pageSize = 500;
#region 获取最大学生ID
//更新账户
......@@ -31,78 +35,81 @@ namespace EduSpider.Spiders.ClassInRule
List<rb_account_hk> accountList = new();
#endregion
while (pageIndex <= pageCount)
while (pageIndex <= pageCount)
{
InfoHelper.WriteLine($"正在查询第{pageIndex}-{pageSize}页学员信息");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"正在查询第{pageIndex}-{pageSize}页学员信息");
var paramStr = $"page={pageIndex}&perpage={pageSize}&isdel=0";
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);
var resultStr = response.Content.ReadAsStringAsync().Result ?? string.Empty;
var result = resultStr.TryToJObject();
if (result.flag)
try
{
var data = (result.val.ContainsKey("data") ? result.val["data"] : new JObject()) as JObject;
if (data.ContainsKey("totalStudentNum")) {
#region 更新PageCount
if (pageIndex == 1)
var response = await request.PostAsync("https://console.eeo.cn/saasajax/student.ajax.php?action=getSchoolStudentListByPage", content);
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;
if (data.ContainsKey("totalStudentNum"))
{
pageCount = (int)Math.Ceiling(data.GetDecimal("totalStudentNum") / pageSize);
}
#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()
#region 更新PageCount
if (pageIndex == 1)
{
AddTime = ConvertHelper.UnixToDateTime(x.GetString("addTime")),
StudentAccount=x.GetString("studentAccount"),
Isdel= x.GetInt("isdel",0),
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
pageCount = (int)Math.Ceiling(data.GetDecimal("totalStudentNum") / pageSize);
}
#endregion
#region 写入账号
if (stus.Any(x => x.StudId > MaxStuId)) {
foreach (var item in stus.Where(x => x.StudId > MaxStuId))
#region 组装实体
var stus = new List<rb_student_hk>();
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,
Id = item.StudId,
Account = item.StudentAccount,
AccountId = item.StudentUid,
AccountType = Utility.Enum.AccountTypeEnum.Student,
OpenId = "",
Password = DESHepler.Encrypt(item.StudentAccount[^6..]),
Status = 0,
UnionId = ""
AddTime = ConvertHelper.UnixToDateTime(x.GetString("addTime")),
StudentAccount = x.GetString("studentAccount"),
Isdel = x.GetInt("isdel", 0),
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 写入账号
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++;
}
......@@ -115,8 +122,6 @@ namespace EduSpider.Spiders.ClassInRule
InfoHelper.WriteLine("学员同步完成");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"学员同步完成");
}
}
}
......@@ -29,39 +29,45 @@ namespace EduSpider.Spiders.ClassInRule
{
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 response = await request.PostAsync("https://console.eeo.cn/saasajax/teacher.ajax.php?action=getSchoolTeacherFullList", content);
var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(result))
try
{
VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}");
JObject rootObj = JObject.Parse(result);
if (!string.IsNullOrWhiteSpace(rootObj.GetString("data")))
var response = await request.PostAsync("https://console.eeo.cn/saasajax/teacher.ajax.php?action=getSchoolTeacherFullList", content);
var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(result))
{
JObject dataObj = JObject.Parse(rootObj.GetString("data"));
var totalNum = dataObj.GetInt("totalNum");
string rlist = dataObj.GetString("list");
if (pageIndex == 1)
VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}");
JObject rootObj = JObject.Parse(result);
if (!string.IsNullOrWhiteSpace(rootObj.GetString("data")))
{
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;
}
else
{
pageCount = (totalNum / perpage) + 1;
if (totalNum % perpage == 0)
{
pageCount = totalNum / perpage;
}
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.WriteInfo("RunTeacher", $"result: {result}");
VTX.FW.Helper.LogHelper.WriteError("RunTeacher",ex:ex);
}
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