Commit fc8ed227 authored by 黄奎's avatar 黄奎

111

parent a7ecb561
......@@ -15,11 +15,10 @@ namespace EduSpider.IRepository
public interface IHomeWorkRepository : IDBRepository<RB_HomeWork>, IDependency
{
/// <summary>
/// 批量添加学生家庭作业
/// 批量添加家庭作业
/// </summary>
/// <param name="homeWorks"></param>
/// <returns></returns>
public bool BatchSetHomeWorkRepository(List<RB_HomeWork> homeWorks);
}
}
using EduSpider.Model.Entity;
using System.Collections.Generic;
using VTX.FW.Config;
using VTX.FW.DB;
namespace EduSpider.IRepository
{
/// <summary>
/// 学生作业仓储层接口
/// </summary>
public interface IStuHomeWorkRepository : IDBRepository<RB_Stu_HomeWork>, IDependency
{
/// <summary>
/// 批量添加学生家庭作业
/// </summary>
/// <param name="homeWorks"></param>
/// <returns></returns>
public bool BatchSetStuHomeWorkRepository(List<RB_Stu_HomeWork> homeWorks);
}
}
......@@ -28,7 +28,7 @@ namespace EduSpider.Model.Entity
/// <summary>
/// 课程编号
/// </summary>
public int? course_id { get; set; }
public int course_id { get; set; }
/// <summary>
/// 课程名称
......@@ -38,77 +38,77 @@ namespace EduSpider.Model.Entity
/// <summary>
/// 作业开始时间
/// </summary>
public DateTime? start_time { get; set; }
public DateTime start_time { get; set; }
/// <summary>
/// 作业结束时间
/// </summary>
public DateTime? end_time { get; set; }
public DateTime end_time { get; set; }
/// <summary>
/// 作业状态(0-未开始,1-进行中,2-已结束)
/// </summary>
public int? status { get; set; }
public int status { get; set; }
/// <summary>
/// 显示状态(0-客户端显示,1-客户端隐藏)
/// </summary>
public int? is_del { get; set; }
public int is_del { get; set; }
/// <summary>
/// 是否公开作业(1-公开作业,2-不公开,3-公开优秀)
/// </summary>
public string is_open { get; set; }
public int is_open { get; set; }
/// <summary>
/// 公开方式(1-结束后)
/// </summary>
public string open_type { get; set; }
public int open_type { get; set; }
/// <summary>
/// 是否允许补交(1-否,2-是)
/// </summary>
public string is_revise { get; set; }
public int is_revise { get; set; }
/// <summary>
/// 学生数
/// </summary>
public int? num { get; set; }
public int num { get; set; }
/// <summary>
/// 优秀人数
/// </summary>
public int? cream_num { get; set; }
public int cream_num { get; set; }
/// <summary>
/// revised_num
/// 补交人数
/// </summary>
public int? revised_num { get; set; }
public int revised_num { get; set; }
/// <summary>
/// 已批阅
/// </summary>
public int? rnum { get; set; }
public int rnum { get; set; }
/// <summary>
/// 已提交
/// </summary>
public int? cnum { get; set; }
public int cnum { get; set; }
/// <summary>
/// 学校编号
/// </summary>
public int? school_uid { get; set; }
public int school_uid { get; set; }
/// <summary>
/// 评分机制(5-自定义,4-不评分,3-等第制,2-十分制,1-百分制)
/// </summary>
public int? score_type { get; set; }
public int score_type { get; set; }
/// <summary>
/// 自定义分数
/// </summary>
public decimal? score_value { get; set; }
public decimal score_value { get; set; }
/// <summary>
/// 教师账号
......@@ -123,7 +123,7 @@ namespace EduSpider.Model.Entity
/// <summary>
/// 教师编号
/// </summary>
public int? teacher_uid { get; set; }
public int teacher_uid { get; set; }
/// <summary>
/// th_cancel
......
using System;
using VTX.FW.Attr;
namespace EduSpider.Model.Entity
{
/// <summary>
/// 课程实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Stu_HomeWork
{
/// <summary>
/// 学生家庭作业主键编号
/// </summary>
public int stu_homework_id { get; set; }
/// <summary>
/// admire
/// </summary>
public string admire { get; set; }
/// <summary>
/// cancel
/// </summary>
public string cancel { get; set; }
/// <summary>
/// 正确数量
/// </summary>
public decimal? correct { get; set; }
/// <summary>
/// 错误题数
/// </summary>
public int? wrong { get; set; }
/// <summary>
/// 课程编号
/// </summary>
public int? course_id { get; set; }
/// <summary>
/// is_cream
/// </summary>
public int? is_cream { get; set; }
/// <summary>
/// emend
/// </summary>
public int? emend { get; set; }
/// <summary>
/// 作业编号
/// </summary>
public int? homework_id { get; set; }
/// <summary>
/// 作业分享Key
/// </summary>
public string homework_share_key { get; set; }
/// <summary>
/// is_draft
/// </summary>
public int? is_draft { get; set; }
/// <summary>
/// is_reform
/// </summary>
public int? is_reform { get; set; }
/// <summary>
/// is_revised
/// </summary>
public int? is_revised { get; set; }
/// <summary>
/// is_startd
/// </summary>
public int? is_startd { get; set; }
/// <summary>
/// readover
/// </summary>
public string readover { get; set; }
/// <summary>
/// 提交时间
/// </summary>
public DateTime? ref_time { get; set; }
/// <summary>
/// 评语
/// </summary>
public string comment { get; set; }
/// <summary>
/// reform
/// </summary>
public string reform { get; set; }
/// <summary>
/// school_uid
/// </summary>
public int? school_uid { get; set; }
/// <summary>
/// 得分
/// </summary>
public decimal? score { get; set; }
/// <summary>
/// 得分率
/// </summary>
public decimal? score_p { get; set; }
/// <summary>
/// 评分机制
/// </summary>
public int? score_type { get; set; }
/// <summary>
/// show_time
/// </summary>
public DateTime? show_time { get; set; }
/// <summary>
/// status
/// </summary>
public string status { get; set; }
/// <summary>
/// 学生作业分享Key
/// </summary>
public string stu_homework_share_key { get; set; }
/// <summary>
/// 学生账号
/// </summary>
public string student_account { get; set; }
/// <summary>
/// 学生姓名
/// </summary>
public string student_name { get; set; }
/// <summary>
/// 学生编号
/// </summary>
public int? student_uid { get; set; }
/// <summary>
/// 教师账号
/// </summary>
public string th_account { get; set; }
/// <summary>
/// th_cancel
/// </summary>
public string th_cancel { get; set; }
/// <summary>
/// 教师姓名
/// </summary>
public string th_name { get; set; }
/// <summary>
/// 教师数量
/// </summary>
public int? th_num { get; set; }
/// <summary>
/// 教师创建时间
/// </summary>
public DateTime? th_time { get; set; }
/// <summary>
/// 教师账号表编号
/// </summary>
public int? th_uid { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? add_time { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime? update_time { get; set; }
}
}
......@@ -11,7 +11,7 @@ namespace EduSpider.Repository
public class HomeWorkRepository : BaseRepository<RB_HomeWork>, IHomeWorkRepository
{
/// <summary>
/// 批量添加学生家庭作业
/// 批量添加家庭作业
/// </summary>
/// <param name="homeWorks"></param>
/// <returns></returns>
......
using EduSpider.IRepository;
using EduSpider.Model.Entity;
using EduSpider.Repository.Base;
using System.Collections.Generic;
namespace EduSpider.Repository
{
/// <summary>
/// 学生作业仓储层实现
/// </summary>
public class StuHomeWorkRepository : BaseRepository<RB_Stu_HomeWork>, IStuHomeWorkRepository
{
/// <summary>
/// 批量添加学生家庭作业
/// </summary>
/// <param name="homeWorks"></param>
/// <returns></returns>
public bool BatchSetStuHomeWorkRepository(List<RB_Stu_HomeWork> homeWorks)
{
bool flag;
flag = base.BatchInsert(homeWorks, isReplace: true);
return flag;
}
}
}
......@@ -25,8 +25,9 @@ namespace TicketSpider.Spiders.ClassInRule
Console.WriteLine("开始获取学员信息");
//new StudentManager().RunAsync(loginCookies);
new CourseManager().RunCourse(loginCookies);
//new CourseManager().RunCourse(loginCookies);
new HomeWorkManager().RunHomeWork(loginCookies);
}
}
}
......@@ -31,7 +31,8 @@ namespace EduSpider.Spiders.ClassInRule
ICourseRepository courseRepository = new CourseRepository();
int totalCount = 0;
Console.WriteLine(string.Format("开始第{0}次获取课程数据", pageCount));
var response = await request.PostAsync("https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseList", content);
string url = "https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseList";
var response = await request.PostAsync(url, content);
var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(result))
{
......@@ -69,8 +70,7 @@ namespace EduSpider.Spiders.ClassInRule
Console.WriteLine(string.Format("第{0}/{1}次获取课程数据", i, pageCount));
paramStr = string.Format(queryStr, i, perpage);
var sub_content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
var sub_response = await request.PostAsync("https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseList", sub_content);
var sub_response = await request.PostAsync(url, sub_content);
var sub_result = sub_response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(sub_result))
{
......@@ -160,7 +160,8 @@ namespace EduSpider.Spiders.ClassInRule
ICourseStudentRepository courseStudentRepository = new CourseStudentRepository();
Console.WriteLine(string.Format("开始获取{0}课程学员数据", courseId));
var response = await request.PostAsync("https://console.eeo.cn/saasajax/student.ajax.php?action=getCourseStudentList", content);
string url = "https://console.eeo.cn/saasajax/student.ajax.php?action=getCourseStudentList";
var response = await request.PostAsync(url, content);
var sutResult = response.Content.ReadAsStringAsync().Result;
List<RB_Course_Student> list = new List<RB_Course_Student>();
if (!string.IsNullOrWhiteSpace(sutResult))
......@@ -207,7 +208,8 @@ namespace EduSpider.Spiders.ClassInRule
ICourseTeacherRepository courseTeacherRepository = new CourseTeacherRepository();
Console.WriteLine(string.Format("开始获取{0}课程老师数据", courseId));
var response = await request.PostAsync("https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseTeacherList", content);
string url = "https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseTeacherList";
var response = await request.PostAsync(url, content);
var teacherResult = response.Content.ReadAsStringAsync().Result;
List<RB_Course_Teacher> list = new List<RB_Course_Teacher>();
if (!string.IsNullOrWhiteSpace(teacherResult))
......@@ -260,7 +262,8 @@ namespace EduSpider.Spiders.ClassInRule
ICourseRepository courseRepository = new CourseRepository();
Console.WriteLine(string.Format("开始获取{0}课程详情数据", courseId));
var response = await request.PostAsync("https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseInfo", content);
string url = "https://console.eeo.cn/saasajax/course.ajax.php?action=getCourseInfo";
var response = await request.PostAsync(url, content);
var courseInfoResult = response.Content.ReadAsStringAsync().Result;
List<RB_Course> list = new List<RB_Course>();
if (!string.IsNullOrWhiteSpace(courseInfoResult))
......
using EduSpider.IRepository;
using EduSpider.Model.Entity;
using EduSpider.Repository;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VTX.FW.Helper;
namespace EduSpider.Spiders.ClassInRule
{
/// <summary>
/// 学生作业
/// </summary>
public class HomeWorkManager
{
/// <summary>
/// 获取学生作业列表
/// </summary>
public async void RunHomeWork(string cookie)
{
int perpage = 20;
var pageCount = 1;
var request = Utility.HttpHelper.GenerateHttp(cookie);
string queryStr = "page={0}&perpage={1}";
string paramStr = string.Format(queryStr, pageCount, perpage);
var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
IHomeWorkRepository homeWorkRepository = new HomeWorkRepository();
int totalCount = 0;
Console.WriteLine(string.Format("开始第{0}次获取家庭作业", pageCount));
string url = "https://console.eeo.cn/saasajax/homework.ajax.php?action=getHomeworkList";
var response = await request.PostAsync(url, content);
var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(result))
{
JObject rootObj = JObject.Parse(result);
if (!string.IsNullOrWhiteSpace(rootObj.GetString("data")))
{
JObject dataObj = JObject.Parse(rootObj.GetString("data"));
var totalNum = dataObj.GetInt("total");
var tempList = ParseJson(dataObj.GetString("list"));
if (tempList != null && tempList.Count > 0)
{
homeWorkRepository.BatchSetHomeWorkRepository(tempList);
totalCount += tempList.Count;
Console.WriteLine(string.Format("第{0}次,导入完成{1}条.", pageCount, totalCount));
foreach (var item in tempList)
{
//TODO
}
}
if (totalNum % perpage == 0)
{
pageCount = totalNum / perpage;
}
else
{
pageCount = totalNum / perpage + 1;
}
if (totalNum > perpage)
{
for (var i = 2; i <= pageCount; i++)
{
Thread.Sleep(1000 * 2);
Console.WriteLine(string.Format("第{0}/{1}次获取课程数据", i, pageCount));
paramStr = string.Format(queryStr, i, perpage);
var sub_content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
var sub_response = await request.PostAsync(url, sub_content);
var sub_result = sub_response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(sub_result))
{
JObject sub_rootObj = JObject.Parse(sub_result);
if (!string.IsNullOrWhiteSpace(sub_rootObj.GetString("data")))
{
JObject sub_dataObj = JObject.Parse(sub_rootObj.GetString("data"));
var subtempList = ParseJson(sub_dataObj.GetString("list"));
if (subtempList != null && subtempList.Count > 0)
{
homeWorkRepository.BatchSetHomeWorkRepository(subtempList);
totalCount += subtempList.Count;
Console.WriteLine(string.Format("第{0}次,导入完成{1}条.", i, totalCount));
foreach (var sItem in subtempList)
{
//TODO
}
}
}
}
}
}
}
}
}
/// <summary>
/// JSON字符串转课程列表
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static List<RB_HomeWork> ParseJson(string data)
{
List<RB_HomeWork> list = new List<RB_HomeWork>();
if (!string.IsNullOrWhiteSpace(data))
{
JArray courseArray = JArray.Parse(data);
if (courseArray != null && courseArray.Count > 0)
{
foreach (var jItem in courseArray)
{
JObject homeObj = JObject.Parse(jItem.ToString());
list.Add(new RB_HomeWork()
{
homework_id = homeObj.GetInt("homework_id"),
homework_title = homeObj.GetString("homework_title"),
homework_share_key = homeObj.GetString("homework_share_key"),
course_id = homeObj.GetInt("course_id"),
course_name = homeObj.GetString("course_name"),
start_time = ConvertHelper.UnixToDateTime(homeObj.GetInt("start_time")),
end_time = ConvertHelper.UnixToDateTime(homeObj.GetInt("end_time")),
status = homeObj.GetInt("status"),
is_del = homeObj.GetInt("is_del"),
is_open = homeObj.GetInt("is_open"),
open_type = homeObj.GetInt("open_type"),
is_revise = homeObj.GetInt("is_revise"),
num = homeObj.GetInt("num"),
cream_num = homeObj.GetInt("cream_num"),
revised_num = homeObj.GetInt("revised_num"),
rnum = homeObj.GetInt("rnum"),
cnum = homeObj.GetInt("cnum"),
school_uid = homeObj.GetInt("school_uid"),
score_type = homeObj.GetInt("score_type"),
score_value = homeObj.GetDecimal("score_value"),
teacher_account = homeObj.GetString("teacher_account"),
teacher_name = homeObj.GetString("teacher_name"),
teacher_uid = homeObj.GetInt("teacher_uid"),
th_cancel = homeObj.GetString("th_cancel"),
add_time = ConvertHelper.UnixToDateTime(homeObj.GetInt("add_time")),
update_time = ConvertHelper.UnixToDateTime(homeObj.GetInt("update_time")),
});
}
}
}
return list;
}
/// <summary>
/// 获取学生提交作业数据
/// </summary>
/// <param name="cookie"></param>
/// <param name="homework_id"></param>
public static void RunStuHomeWork(string cookie, int homework_id)
{
}
}
}
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