Beispiel #1
0
func UpdateEduLog(userPtr *EduLog) error {
	if err := checkEduLog(userPtr); err != nil {
		return models.ErrorInfo("UpdateEduLog", err)
	}
	_, err := orm.NewOrm().Update(userPtr)
	if err != nil {
		return models.ErrorInfo("UpdateEduLog", err)
	}
	return nil
}
Beispiel #2
0
func AddEduLog(userPtr *EduLog) error {
	if err := checkEduLog(userPtr); err != nil {
		return models.ErrorInfo("AddEduLog", err)
	}
	_, err := orm.NewOrm().Insert(userPtr)
	if err != nil {
		return models.ErrorInfo("AddEduLog", err)
	}
	return nil
}
Beispiel #3
0
func GetUserClassLog(s_id string) ([]*EduLog, error) {
	var result []*EduLog
	_, err := orm.NewOrm().QueryTable("EduLog").Filter("Student", s_id).Filter("Type", "class").Filter("Result", 1).OrderBy("-ControlTime").All(&result)
	if err != nil {
		return nil, models.ErrorInfo("GetUserClassLog", err)
	}
	return result, nil
}
Beispiel #4
0
func GetUserinfoLog(s_id string) (*EduLog, error) {
	var result EduLog
	err := orm.NewOrm().QueryTable("EduLog").Filter("Student", s_id).Filter("Type", "userProfile").Filter("Result", 1).OrderBy("-ControlTime").Limit(1).One(&result)
	if err != nil {
		return nil, models.ErrorInfo("GetUserinfoLog", err)
	}
	return &result, nil
}
Beispiel #5
0
func EduLogCreate(userPtr *EduLog) error {
	if err := checkEduLog(userPtr); err != nil {
		return models.ErrorInfo("EduLogCreate", err)
	}
	switch userPtr.Type {
	case "userProfile":
		if edu_log, _ := GetUserinfoLog(userPtr.Student.Id); edu_log != nil {
			userPtr.ControlTime = time.Now()
			return models.ErrorInfo("EduLogCreate", UpdateEduLog(userPtr))
		} else {
			return models.ErrorInfo("EduLogCreate", AddEduLog(userPtr))
		}
	default:
		return models.ErrorInfo("EduLogCreate", AddEduLog(userPtr))
	}
	return models.ErrorInfo("EduLogCreate", "no change")
}
Beispiel #6
0
func GetStudentProfile(data []byte, cookies []*http.Cookie) (map[string]string, error) {
	if data == nil {
		return nil, models.ErrorInfo("GetStudentProfile", errors.New("data in nil"))
	}
	userinfohref, _ := getUserInfoHref(string(data))
	userinfo_data, _, err := client.SendRequest("GET", Host_url+"/"+userinfohref, "", cookies, header)
	if err != nil {
		return nil, models.ErrorInfo("GetStudentProfile", err)
	}
	userinfo, _ := getUserInfo(string(userinfo_data))
	userimg, _, err := client.SendRequest("GET", Host_url+"/readimagexs.aspx?xh="+userinfo["学号"], "", cookies, nil)
	if err != nil {
		return nil, models.ErrorInfo("GetStudentProfile", errors.New("readimg is failed"))
	}
	if path, err := models.SaveFile("EDU/headimg/", userinfo["学号"], "jpg", userimg); err == nil {
		userinfo["头像"] = path
	}
	return userinfo, nil
}
Beispiel #7
0
func checkEduLog(u *EduLog) (err error) {
	valid := validation.Validation{}
	b, _ := valid.Valid(u)
	if !b {
		for _, err := range valid.Errors {
			return models.ErrorInfo("checkEduLog", err)
		}
	}
	return nil
}
Beispiel #8
0
func GetStudentScore(user *models.Student, data []byte, cookies []*http.Cookie) (map[string]map[string]string, error) {
	userscorehref, _ := getUserScoreHref(string(data))
	userscore_param, _, err := client.SendRequest("GET", Host_url+"/"+userscorehref, "", cookies, header)
	if err != nil {
		return nil, models.ErrorInfo("GetStudentScore", errors.New("连接失败,错误原因:"+err.Error()))
	}
	vierstate, eventvalidation, _ := getLoginKey(string(userscore_param))
	userscore_info, _, err := client.SendRequest("POST", Host_url+"/"+userscorehref, url.Values{
		"__VIEWSTATE":       {vierstate},
		"__EVENTVALIDATION": {eventvalidation},
		"ddIXN":             {""},
		"ddIXQ":             {""},
		"Button1":           {models.Utf82gbk("按学期查询")},
	}.Encode(), cookies, header)
	if err != nil {
		return nil, models.ErrorInfo("GetStudentScore", errors.New("连接失败,错误原因:"+err.Error()))
	}
	userscore, _ := getUserScore(string(userscore_info))
	for _, v := range userscore {
		if len(v) > 0 {
			if exist := models.CourseExist(v["课程名称"]); !exist {
				if exist := models.DepartmentExist(v["学院名称"]); !exist {
					if _, err := models.AddDepartment(&models.Department{Name: v["学院名称"]}); err == nil {
						EduLogCreate(&EduLog{Student: user, Content: v["学院名称"], Type: "department", Result: 1})
					} else {
						EduLogCreate(&EduLog{Student: user, Content: v["学院名称"], Type: "department", Result: 0})
					}
				}
				if department, err := models.GetDepartmentByName(v["学院名称"]); err == nil {
					f, _ := strconv.ParseFloat(v["学分"], 64)
					if err := models.AddCourse(&models.Course{Id: v["课程代码"], Name: v["课程名称"], Department: department, Remark: v["课程归属"], Type: v["课程性质"], Credit: f}); err == nil {
						EduLogCreate(&EduLog{Student: user, Content: v["课程名称"], Type: "course", Result: 1})
					} else {
						EduLogCreate(&EduLog{Student: user, Content: v["课程名称"], Type: "course", Result: 0})
					}
				}
			}
		}
	}
	return userscore, nil
}
Beispiel #9
0
func Sign_in(id, pwd, user_type string) ([]byte, bool, []*http.Cookie, error) {
	if user_type != "学生" && user_type != "教师" {
		return nil, false, nil, models.ErrorInfo("Sign_in", errors.New("user type is error:"+user_type))
	}
	if len(id) <= 0 || len(pwd) <= 0 {
		return nil, false, nil, models.ErrorInfo("Sign_in", errors.New("id or pwd is error:["+id+"_"+pwd+"]"))
	}
	data, cookies, err := client.SendRequest("GET", Host_url, "", nil, nil)
	if err != nil {
		return nil, false, nil, models.ErrorInfo("Sign_in", err)
	}
	vierstate, eventvalidation, err := getLoginKey(string(data))
	if err != nil {
		return nil, false, nil, models.ErrorInfo("Sign_in", err)
	}
	//	sigin...
	post_arg := url.Values{
		"__VIEWSTATE":       {vierstate},
		"__EVENTVALIDATION": {eventvalidation},
		"TextBox1":          {id},
		"TextBox2":          {pwd},
		"RadioButtonList1":  {models.Utf82gbk(user_type)},
		"Button1":           {""},
	}
	//	登陆
	main_data, _, err := client.SendRequest("POST", Host_url+"/default2.aspx", post_arg.Encode(), cookies, header)
	if err != nil {
		return nil, false, nil, models.ErrorInfo("Sign_in", err)
	}
	//	判断是否登录失败
	if strings.Contains(string(main_data), "<title>登录</title>") {
		return nil, false, nil, models.ErrorInfo("Sign_in", errors.New("id or pwd not match"))
	}
	return main_data, true, cookies, nil
}
Beispiel #10
0
func GetStudentSchedule(user *models.Student, data []byte, cookies []*http.Cookie) (schedules map[*models.Term][]*models.TeacherCourse, err error) {
	if data == nil {
		return nil, models.ErrorInfo("GetStudentSchedule", errors.New("data in nil"))
	}
	userschedulehref, _ := getUserScheduleHref(string(data))
	userschedule_data, _, err := client.SendRequest("GET", Host_url+"/"+userschedulehref, "", cookies, header)
	if err != nil {
		return nil, models.ErrorInfo("GetStudentSchedule", err)
	}

	//	获取当前学年度的学期
	xq, _ := getUserXQ(string(userschedule_data))
	//	根据用户的入学年份和当前学年度的学期 列出学期列表
	xqs, err := getXQS(xq, user.EnterSchoolYear)
	if err != nil {
		return nil, models.ErrorInfo("GetStudentSchedule", err)
	}
	//	查询历年课表
	schedules = make(map[*models.Term][]*models.TeacherCourse, len(xqs))
	userschedule_xq_href, _ := getUserScheduleXQHref(string(userschedule_data))
	vierstate, eventvalidation, _ := getLoginKey(string(userschedule_data))
	for _, v := range xqs {
		//	判断学期是否存在 如果不存在则添加
		if len(v["学年度"]) > 0 {
			if years := strings.Split(v["学年度"], "-"); len(years) == 2 {
				startyear, _ := strconv.Atoi(years[0])
				endyear, _ := strconv.Atoi(years[1])
				if len(v["学期"]) > 0 {
					num, _ := strconv.Atoi(v["学期"])
					if exist := models.TermExist(num, startyear, endyear); !exist {
						if err := models.AddTerm(&models.Term{Number: num, StartYear: startyear, EndYear: endyear}); err == nil {
							EduLogCreate(&EduLog{Student: user, Content: `{"学年度": "` + v["学年度"] + `", "学期": "` + v["学期"] + `"}`, Type: "term", Result: 1})
						} else {
							EduLogCreate(&EduLog{Student: user, Content: `{"学年度": "` + v["学年度"] + `", "学期": "` + v["学期"] + `"}`, Type: "term", Result: 0})
						}
					}
					//	查询学期
					term, err := models.SearchTerm(num, startyear, endyear)
					if err != nil {
						models.Info("EduGetStudentSchedule", err)
						continue
					}
					//	获取login key
					userschedule_temp_data, _, err := client.SendRequest("POST", Host_url+"/"+userschedule_xq_href, url.Values{
						"__EVENTTARGET":     {"ddlXQ"},
						"__EVENTARGUMENT":   {""},
						"__LASTFOCUS":       {""},
						"__VIEWSTATE":       {vierstate},
						"__EVENTVALIDATION": {eventvalidation},
						"ddlXN":             {fmt.Sprintf("%d-%d", term.StartYear, term.EndYear)},
						"ddlXQ":             {fmt.Sprintf("%d", term.Number)},
					}.Encode(), cookies, header)
					if err != nil {
						EduLogCreate(&EduLog{Student: user, Content: `获取` + v["学年度"] + ` ` + v["学期"] + `课表失败`, Type: "t_course", Result: 0})
						continue
					}
					if !strings.Contains(string(userschedule_temp_data), `<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET"`) {
						EduLogCreate(&EduLog{Student: user, Content: `获取` + v["学年度"] + ` ` + v["学期"] + `课表失败`, Type: "t_course", Result: 0})
						continue
					}
					usercourse, _, _ := getUserCourse(string(userschedule_temp_data), cookies)
					if usercourse == nil {
						EduLogCreate(&EduLog{Student: user, Content: `获取` + v["学年度"] + ` ` + v["学期"] + `课表失败`, Type: "t_course", Result: 0})
						continue
					}
					// schedules[term] = make([]*models.TeacherCourse, len(usercourse))
					for _, v := range usercourse {
						if len(v) > 0 {
							if exist := models.CourseExist(v["课程名称"]); !exist {
								if exist := models.DepartmentExist(v["教师所在系"]); !exist {
									if _, err := models.AddDepartment(&models.Department{Name: v["教师所在系"]}); err == nil {
										EduLogCreate(&EduLog{Student: user, Content: v["教师所在系"], Type: "department", Result: 1})
									} else {
										EduLogCreate(&EduLog{Student: user, Content: v["教师所在系"], Type: "department", Result: 0})
									}
								}
								if department, err := models.GetDepartmentByName(v["教师所在系"]); err == nil {
									if exist := models.TeacherExistByDep(v["教师姓名"], department.Id); !exist {
										if err := models.AddTeacher(&models.Teacher{Name: v["教师姓名"], Department: department, Password: "******", Headimgurl: "/static/img/avatar.jpeg"}); err == nil {
											EduLogCreate(&EduLog{Student: user, Content: v["教师姓名"], Type: "teacher", Result: 1})
										} else {
											EduLogCreate(&EduLog{Student: user, Content: v["教师姓名"], Type: "teacher", Result: 0})
										}
									}
									f, _ := strconv.ParseFloat(v["学分"], 64)
									if err := models.AddCourse(&models.Course{Id: v["课程代码"], Name: v["课程名称"], Department: department, Type: v["课程性质"], Credit: f}); err == nil {
										EduLogCreate(&EduLog{Student: user, Content: v["课程名称"], Type: "course", Result: 1})
									} else {
										EduLogCreate(&EduLog{Student: user, Content: v["课程名称"], Type: "course", Result: 0})
									}
								}
							}
							if department, err := models.GetDepartmentByName(v["教师所在系"]); err == nil {
								if teacher, err := models.SearchTeacher(v["教师姓名"], department.Id); err == nil {
									//	search course
									if course, err := models.SearchCourse(v["课程名称"]); err == nil {
										if courseTime := getTime(v["上课时间"]); courseTime != nil {
											for _, v1 := range courseTime {
												end_week, _ := strconv.Atoi(v1["end_week"])
												start_week, _ := strconv.Atoi(v1["start_week"])
												spacing, _ := strconv.Atoi(v1["spacing"])
												time := `{"week_day":"` + v1["week_day"] + `", "week_time":"` + v1["time"] + `"}`
												//	add m2m between teacher and course
												if exist := models.TeacherCourseExist(course.Id, time, term.Id, teacher.Id); !exist {
													var teacher_course = &models.TeacherCourse{Course: course,
														Term:      term,
														Teacher:   teacher,
														Place:     v["上课地点"],
														StartWeek: start_week,
														EndWeek:   end_week,
														Time:      time,
														Remark:    v1["remark"],
														Spacing:   spacing,
													}
													if err := models.AddTeacherCourse(teacher_course); err == nil {
														EduLogCreate(&EduLog{Student: user, Content: `教师 ` + teacher_course.Teacher.Name + ` 教授的课程:` + teacher_course.Course.Name + `, 上课时间:` + v["上课时间"] + `, 上课地点:` + v["上课地点"], Type: "t_course", Result: 1})
													} else {
														models.Info("EduGetStudentSchedule", err)
														EduLogCreate(&EduLog{Student: user, Content: `教师 ` + teacher_course.Teacher.Name + ` 教授的课程:` + teacher_course.Course.Name + `, 上课时间:` + v["上课时间"] + `, 上课地点:` + v["上课地点"], Type: "t_course", Result: 0})
													}
												}
												//	search teacher course
												if t_course, err := models.SearchTeacherCourse(course.Id, time, term.Id, teacher.Id); err == nil {
													// add m2m between teacher_course and class
													if exist := models.ExistTeacherCourseAndClass(t_course.Id, user.Class.Id); !exist {
														if err := models.AddM2MBetweenTeacherCourseAndClass(t_course.Id, user.Class.Id); err == nil {
															EduLogCreate(&EduLog{Student: user, Content: `教师 ` + t_course.Teacher.Name + ` 教授的课程:` + t_course.Course.Name + `,班级:` + user.Class.Name, Type: "t_course_class", Result: 1})
														} else {
															EduLogCreate(&EduLog{Student: user, Content: `教师 ` + t_course.Teacher.Name + ` 教授的课程:` + t_course.Course.Name + `,班级:` + user.Class.Name, Type: "t_course_class", Result: 0})
														}
													}
													//	add m2m between teacher_course and student
													if exist := models.StudentCourseExist(user.Id, t_course.Id); !exist {
														//	add student course
														if err := models.AddStudentCourse(&models.StudentCourse{Student: user, TeacherCourse: t_course}); err == nil {
															EduLogCreate(&EduLog{Student: user, Content: `教师 ` + t_course.Teacher.Name + ` 教授的课程:` + t_course.Course.Name + `, 上课时间:` + v["上课时间"] + `, 上课地点:` + v["上课地点"], Type: "s_course", Result: 1})
														} else {
															EduLogCreate(&EduLog{Student: user, Content: `教师 ` + t_course.Teacher.Name + ` 教授的课程:` + t_course.Course.Name + `, 上课时间:` + v["上课时间"] + `, 上课地点:` + v["上课地点"], Type: "s_course", Result: 0})
														}
													}
													schedules[term] = append(schedules[term], t_course)
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return schedules, nil
}
Beispiel #11
0
func getUserCourse(data string, cookies []*http.Cookie) (info []map[string]string, xq map[string]string, err error) {
	if len(data) <= 0 {
		return nil, nil, errors.New("getUserCourse: data is null")
	}
	xq = make(map[string]string, 2)
	//	取出学年度数据
	re, _ := regexp.Compile(`<option selected="selected" value="([\d-]*)">[\d-]*</option>`)
	maps := re.FindStringSubmatch(data)
	if len(maps) <= 0 {
		return nil, nil, errors.New("getUserCourse: school year is null")
	}
	xq["学年度"] = maps[1]
	//	取出学期数据
	re, _ = regexp.Compile(`<option selected="selected" value="([\d])">[\d]</option>`)
	maps = re.FindStringSubmatch(data)
	if len(maps) < 0 {
		return nil, nil, errors.New("getUserCourse: term is null")
	}
	xq["学期"] = maps[1]
	//	取出table内容
	re, _ = regexp.Compile(`<table class="datelist " cellspacing="0" cellpadding="3" border="0" id="DBGrid" style="width:100%;border-collapse:collapse;">([\s\S]*)</table>[\s\S]*</span>`)
	maps = re.FindStringSubmatch(data)
	if len(maps) <= 0 {
		return nil, nil, errors.New("getUserScore: table is null")
	}
	var key []string
	//	按 </tr> 截取
	arr := strings.Split(maps[1], "</tr>")
	for k, v := range arr {
		//	取出td中的内容
		re, _ = regexp.Compile(`<td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td( title="([\s\S]*)"){0,1}>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td><td>([\s\S]*)</td>`)
		maps1 := re.FindStringSubmatch(v)
		if len(maps1) > 0 {
			if k == 0 {
				key = maps1[1:]
			} else {
				var s = make(map[string]string, 11)
				for k1, v1 := range maps1 {
					if k1 == 0 {
						continue
					}
					data = strings.Replace(data, "&nbsp;", "-", -1)
					if key[k1-1] == "上课时间" {
						if string(v1[len(v1)-1]) != "}" {
							s[key[k1-1]] = maps1[k1-1]
						} else {
							s[key[k1-1]] = v1
						}
					} else {
						s[key[k1-1]] = v1
					}
				}
				info = append(info, s)
			}
		}
	}
	for k, v := range info {
		re1, _ := regexp.Compile(`<a href='#' onclick="window.open\('kcxx\.aspx\?kcdm=(.*)','kcxx','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=490,height=500,left=200,top=50'\)">(.*)</a>`)
		maps2 := re1.FindStringSubmatch(v["课程名称"])
		if len(maps2) <= 0 {
			continue
		}
		info[k]["课程代码"] = maps2[1]
		info[k]["课程名称"] = maps2[2]
		//	获取教师姓名与教师所在学院
		re, _ = regexp.Compile(`<a href='#' onclick="window.open\('(.*)','jsxx','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=800,height=600,left=120,top=60'\)">(.*)</a>`)
		maps3 := re.FindStringSubmatch(v["教师姓名"])
		if len(maps3) <= 0 {
			continue
		}
		info[k]["教师姓名"] = maps3[2]
		//	发送连接获取教师所在的系
		data, _, err := client.SendRequest("GET", Host_url+"/"+maps3[1], "", cookies, header)
		if err != nil {
			return nil, nil, models.ErrorInfo("getUserCourse", err)
		}
		re3, _ := regexp.Compile(`<TD><span id="bm">(.*)</span></TD>`)
		maps4 := re3.FindStringSubmatch(string(data))
		if len(maps4) <= 0 {
			continue
		}
		info[k]["教师所在系"] = maps4[1]
	}
	return info, xq, nil
}
Beispiel #12
0
func UpdateStudentProfile(user *models.Student, userinfo map[string]string) error {
	if userinfo == nil {
		return models.ErrorInfo("UpdateStudentProfile", errors.New("userinfo is nil"))
	}
	if user == nil || user.Id != userinfo["学号"] {
		return models.ErrorInfo("UpdateStudentProfile", errors.New("用户与学号不匹配"))
	}
	user.Name = userinfo["姓名"]
	user.IsEdu = true
	if userinfo["性别"] == "男" {
		user.Sex = 1
	} else if userinfo["性别"] == "女" {
		user.Sex = 2
	}
	user.Headimgurl = userinfo["头像"]
	enterSchoolYear, _ := strconv.Atoi(userinfo["当前所在级"])
	user.EnterSchoolYear = enterSchoolYear
	enterSchoolDate, _ := strconv.Atoi(userinfo["入学日期"])
	user.EnterSchoolDate = enterSchoolDate
	idcard, _ := strconv.ParseInt(userinfo["身份证号"], 10, 64)
	user.IdCard = idcard

	if len(userinfo["系"]) > 0 {
		if exist := models.DepartmentExist(userinfo["系"]); !exist {
			_, err := models.AddDepartment(&models.Department{Name: userinfo["系"]})
			if err != nil {
				EduLogCreate(&EduLog{Student: user, Content: userinfo["系"], Type: "department", Result: 0})
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			EduLogCreate(&EduLog{Student: user, Content: userinfo["系"], Type: "department", Result: 1})
		}
	}
	if len(userinfo["专业名称"]) > 0 {
		if exist := models.MajorExist(userinfo["专业名称"]); !exist {
			department, err := models.GetDepartmentByName(userinfo["系"])
			if err != nil {
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			_, err = models.AddMajor(&models.Major{Name: userinfo["专业名称"], Department: department})
			if err != nil {
				EduLogCreate(&EduLog{Student: user, Content: userinfo["专业名称"], Type: "major", Result: 0})
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			EduLogCreate(&EduLog{Student: user, Content: userinfo["专业名称"], Type: "major", Result: 1})
		}
	}
	if len(userinfo["行政班"]) > 0 {
		if exist := models.ClassExist(userinfo["行政班"]); !exist {
			department, err := models.GetDepartmentByName(userinfo["系"])
			if err != nil {
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			major, err := models.GetMajorByName(userinfo["专业名称"])
			if err != nil {
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			_, err = models.AddClass(&models.Class{Name: userinfo["行政班"], Department: department, Major: major})
			if err != nil {
				EduLogCreate(&EduLog{Student: user, Content: userinfo["行政班"], Type: "class", Result: 0})
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			EduLogCreate(&EduLog{Student: user, Content: userinfo["行政班"], Type: "class", Result: 1})
		}
	}
	department, _ := models.GetDepartmentByName(userinfo["系"])
	major, _ := models.GetMajorByName(userinfo["专业名称"])
	class, _ := models.GetClassByName(userinfo["行政班"])
	user.Department = department
	user.Major = major
	user.Class = class
	if err := models.UpdateStudent(user); err != nil {
		return models.ErrorInfo("UpdateStudentProfile", err)
	}
	return nil
}
Beispiel #13
0
func ControlSQLByScheduleAndScore(user *models.Student, schedules map[*models.Term][]*models.TeacherCourse, score map[string]map[string]string) error {
	if user == nil || len(schedules) <= 0 || len(score) <= 0 {
		return models.ErrorInfo("ControlSQLByScheduleAndScore", errors.New("user is nil"))
	}
	for k, v := range schedules {
		//	取出学年度 学期
		if k == nil || v == nil {
			continue
		}
		if exist := models.TermExist(k.Number, k.StartYear, k.EndYear); !exist {
			if err := models.AddTerm(k); err == nil {
				EduLogCreate(&EduLog{Student: user, Content: `{"学年度": "` + fmt.Sprintf("%d", k.StartYear) + `-` + fmt.Sprintf("%d", k.EndYear) + `", "学期": "` + fmt.Sprintf("%d", k.Number) + `"}`, Type: "term", Result: 1})
			} else {
				EduLogCreate(&EduLog{Student: user, Content: `{"学年度": "` + fmt.Sprintf("%d", k.StartYear) + `-` + fmt.Sprintf("%d", k.EndYear) + `", "学期": "` + fmt.Sprintf("%d", k.Number) + `"}`, Type: "term", Result: 0})
			}
		}
		_, err := models.SearchTerm(k.Number, k.StartYear, k.EndYear)
		if err != nil {
			models.Info("ControlSQLByScheduleAndScore", err)
			continue
		}
		for _, t_course := range v {
			if exist := models.TeacherCourseExist(t_course.Course.Id, t_course.Time, t_course.Term.Id, t_course.Teacher.Id); !exist {
				//	add teacher course
				if err := models.AddTeacherCourse(t_course); err == nil {
					EduLogCreate(&EduLog{Student: user, Content: `教师 ` + t_course.Teacher.Name + ` 教授的课程:` + t_course.Course.Name + `, 上课时间:` + t_course.Time + `, 上课地点:` + t_course.Place, Type: "t_course", Result: 1})
				} else {
					models.Info("EduGetStudentSchedule", err)
					EduLogCreate(&EduLog{Student: user, Content: `教师 ` + t_course.Teacher.Name + ` 教授的课程:` + t_course.Course.Name + `, 上课时间:` + t_course.Time + `, 上课地点:` + t_course.Place, Type: "t_course", Result: 0})
				}
			}
			if temp_t_course, err := models.SearchTeacherCourse(t_course.Course.Id, t_course.Time, t_course.Term.Id, t_course.Teacher.Id); err == nil {
				if exist := models.StudentCourseExist(user.Id, temp_t_course.Id); !exist {
					//	add student course
					if err := models.AddStudentCourse(&models.StudentCourse{Student: user, TeacherCourse: temp_t_course}); err == nil {
						EduLogCreate(&EduLog{Student: user, Content: `教师 ` + temp_t_course.Teacher.Name + ` 教授的课程:` + temp_t_course.Course.Name + `, 上课时间:` + temp_t_course.Time + `, 上课地点:` + temp_t_course.Place, Type: "s_course", Result: 1})
					} else {
						EduLogCreate(&EduLog{Student: user, Content: `教师 ` + temp_t_course.Teacher.Name + ` 教授的课程:` + temp_t_course.Course.Name + `, 上课时间:` + temp_t_course.Time + `, 上课地点:` + temp_t_course.Place, Type: "s_course", Result: 0})
					}
				}
				if temp_s_course, err := models.SearchStudentCourse(user.Id, temp_t_course.Id); err == nil {
					if exist := models.StudentGradeExist(temp_s_course.Id); !exist {
						//	取出成绩
						var (
							score = score[t_course.Course.Id]
							grade = 0
						)
						if score["重修成绩"] != "-" {
							num, _ := strconv.Atoi(score["重修成绩"])
							grade = num
						} else if score["补考成绩"] != "-" {
							num, _ := strconv.Atoi(score["补考成绩"])
							grade = num
						} else if len(score["成绩"]) > 0 {
							num, _ := strconv.Atoi(score["成绩"])
							grade = num
						}
						gpa, _ := strconv.ParseFloat(score["绩点"], 64)
						if err := models.AddStudentGrade(&models.StudentGrade{StudentCourse: temp_s_course, GradePointAverage: gpa, Grade: grade}); err == nil {
							EduLogCreate(&EduLog{Student: user, Content: `科目:` + temp_s_course.TeacherCourse.Course.Name + `的成绩为:` + fmt.Sprintf("%d", grade) + `,绩点为:` + fmt.Sprintf("%.2f", gpa), Type: "s_course_grade", Result: 1})
						} else {
							EduLogCreate(&EduLog{Student: user, Content: `科目:` + temp_s_course.TeacherCourse.Course.Name + `的成绩为:` + fmt.Sprintf("%d", grade) + `,绩点为:` + fmt.Sprintf("%.2f", gpa), Type: "s_course_grade", Result: 0})
						}
					} else {
						//	取出成绩
						var (
							score = score[t_course.Course.Id]
							grade = 0
						)
						if score["重修成绩"] != "-" {
							num, _ := strconv.Atoi(score["重修成绩"])
							grade = num
						} else if score["补考成绩"] != "-" {
							num, _ := strconv.Atoi(score["补考成绩"])
							grade = num
						} else if len(score["成绩"]) > 0 {
							num, _ := strconv.Atoi(score["成绩"])
							grade = num
						}
						gpa, _ := strconv.ParseFloat(score["绩点"], 64)
						//	查找成绩
						if student_grades, err := models.SearchStudentGradeByStudentCourse(temp_s_course); err == nil {
							for _, v := range student_grades {
								//	更新
								models.UpdateStudentGrade(&models.StudentGrade{Id: v.Id, StudentCourse: temp_s_course, GradePointAverage: gpa, Grade: grade})
							}
						}
					}
				}
			}
		}
	}
	return nil
}