Пример #1
0
// @Title 根据学年度 学期 与 教师 获取教师课程表
// @router /getStudentCourseByTerm [post]
func (this *APIStudentController) GetStudentCourseByTerm() {
	xnd := this.GetString("xnd")
	if len(xnd) > 0 {
		arr := strings.Split(xnd, "-")
		if len(arr) == 2 {
			startYear, _ := strconv.Atoi(arr[0])
			endYear, _ := strconv.Atoi(arr[1])
			xqd, _ := this.GetInt("xqd")
			if term, err := models.SearchTerm(xqd, startYear, endYear); err == nil {
				s_id := this.GetSession("id").(string)
				if s_courses, err := models.GetStudentCourseByTerm(term, s_id); err == nil {
					this.SendSuccessJSON(s_courses)
					return
				} else {
					this.SendFailedJSON(1, "获取教师课程表失败")
					return
				}
			} else {
				this.SendFailedJSON(1, "获取学期数据失败")
				return
			}

		}
	}
	this.SendFailedJSON(1, "学年度不正确")
	return
}
Пример #2
0
// @Title 课程表视图
// @router /table [get]
func (this *ViewStudentController) Table() {
	change, _ := this.GetBool("change")
	this.Data["change"] = change
	//	get the term list
	term_list, err := models.GetTermListByStudentCourse(this.Data["student"].(*models.Student).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	this.Data["term_list"] = models.RankingTerm(term_list)
	var term *models.Term
	xnd := this.GetString("xnd")
	if len(xnd) > 0 {
		xqd, _ := this.GetInt("xqd")
		arr := strings.Split(xnd, "-")
		if len(arr) != 2 {
			this.Redirect("/error", 302)
			this.StopRun()
		}
		startYear, _ := strconv.Atoi(arr[0])
		endYear, _ := strconv.Atoi(arr[1])
		term, err = models.SearchTerm(xqd, startYear, endYear)
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	} else {
		//	get the now term
		term, err = models.GetTermByTimeNow()
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	}
	this.Data["term"] = term
	//	get the student course
	s_courses, err := models.GetStudentCourseByTerm(term, this.Data["student"].(*models.Student).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	this.Data["course_color"] = []string{"tb-red", "tb-dark-blue", "tb-grey", "tb-violet", "tb-origin", "tb-blue-green", "tb-blue", "tb-yellow",
		"tb-green", "tb-light-blue", "tb-brown", "tb-pink", "tb-light-green", "tb-dark-blue", "tb-rose-red"}
	this.Data["course_time"] = []string{"08:00-08:40", "08:50-09:30", "09:45-10:25", "10:35-11:15", "11:20-12:00",
		"12:50-13:30", "13:40-14:20", "14:30-15:10", "15:15-15:55", "16:10-16:50", "16:55-17:35", "18:45-19:25",
		"19:30-20:10", "20:15-20:55", "21:05-21:45"}
	this.Data["course_week"] = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}
	this.Data["s_courses"] = models.RangeToMapStudentCourse(s_courses)
	this.Data["now_week"] = this.GetString("week")

	this.Layout = "student/base.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Head_html"] = "student/head/table_head.html"
	this.LayoutSections["Scripts"] = "student/scripts/table_scripts.html"
	this.TplNames = "student/table.html"
}
Пример #3
0
// @Tilte 我的成绩
// @router /studentScore [get]
func (this *ViewStudentController) StudentScore() {
	//	get the term list
	term_list, err := models.GetTermListByStudentCourse(this.Data["student"].(*models.Student).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}

	var term *models.Term
	xnd := this.GetString("xnd")
	if len(xnd) > 0 {
		xqd, _ := this.GetInt("xqd")
		arr := strings.Split(xnd, "-")
		if len(arr) != 2 {
			this.Redirect("/error", 302)
			this.StopRun()
		}
		startYear, _ := strconv.Atoi(arr[0])
		endYear, _ := strconv.Atoi(arr[1])
		term, err = models.SearchTerm(xqd, startYear, endYear)
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	} else {
		//	get the now term
		term, err = models.GetTermByTimeNow()
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	}
	this.Data["term"] = term
	//	get the student course
	if s_courses, err := models.GetStudentCourseByTerm(term, this.Data["student"].(*models.Student).Id); err == nil {
		s_courses = models.FilterRepeat(s_courses).([]*models.StudentCourse)
		//	get the score
		for k, v := range s_courses {
			if score, err := models.SearchStudentGrade(v.Id); err == nil {
				s_courses[k].Score = score
			} else {
				continue
			}
		}
		this.Data["s_courses"] = s_courses
		for k, v := range term_list {
			if term.Id == v.Id {
				term_list[k].Orgs = make(map[string]interface{})
				for k1, _ := range s_courses {
					s_courses[k1].TeacherCourse.Term = nil
					s_courses[k1].Score.StudentCourse = nil
				}
				term_list[k].Orgs["s_course"] = s_courses
			}
		}
	} else {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	//	get all student course
	for k, v := range term_list {
		if term.Id != v.Id {
			term_list[k].Orgs = make(map[string]interface{})

			if s_courses, err := models.GetStudentCourseByTerm(term_list[k], this.Data["student"].(*models.Student).Id); err == nil {
				s_courses = models.FilterRepeat(s_courses).([]*models.StudentCourse)
				//	get the score
				for k, v := range s_courses {
					if score, err := models.SearchStudentGrade(v.Id); err == nil {
						score.StudentCourse = nil
						s_courses[k].TeacherCourse.Term = nil
						s_courses[k].Score = score
					} else {
						continue
					}
				}
				term_list[k].Orgs["s_course"] = s_courses
			}
		}
	}
	this.Data["term_list"] = models.RankingTerm(term_list)

	this.Layout = "student/base.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Head_html"] = "student/head/score_head.html"
	this.LayoutSections["Scripts"] = "student/scripts/score_scripts.html"
	this.TplNames = "student/score.html"
}
Пример #4
0
// @Title 作业统计
// @router /studentHomework [get]
func (this *ViewStudentController) StudentHomework() {
	//	get the term list
	term_list, err := models.GetTermListByStudentCourse(this.Data["student"].(*models.Student).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	var term *models.Term
	xnd := this.GetString("xnd")
	if len(xnd) > 0 {
		xqd, _ := this.GetInt("xqd")
		arr := strings.Split(xnd, "-")
		if len(arr) != 2 {
			this.Redirect("/error", 302)
			this.StopRun()
		}
		startYear, _ := strconv.Atoi(arr[0])
		endYear, _ := strconv.Atoi(arr[1])
		term, err = models.SearchTerm(xqd, startYear, endYear)
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	} else {
		//	get the now term
		term, err = models.GetTermByTimeNow()
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	}
	this.Data["term"] = term
	//	get the student course
	s_course_id, _ := this.GetInt64("course")
	if s_course_id > 0 {
		if s_course, err := models.GetStudentCourseById(s_course_id); err == nil {
			this.Data["s_course"] = s_course
		} else {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	}
	//	get the student courses
	if s_courses, err := models.GetStudentCourseByTerm(term, this.Data["student"].(*models.Student).Id); err == nil {
		//	get the student homework
		for k, v := range s_courses {
			if s_homeworks, err := models.GetStudentHomeworkByStudentCourse(v, this.Data["student"].(*models.Student).Id); err == nil {
				s_courses[k].Orgs = make(map[string]interface{})
				s_courses[k].Orgs["s_homeworks"] = s_homeworks
				for k, v := range term_list {
					if term.Id == v.Id {
						term_list[k].Orgs = make(map[string]interface{})
						term_list[k].Orgs["s_course"] = s_courses
					}
				}
			} else {
				continue
			}
		}
		this.Data["s_courses"] = s_courses
	} else {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	//	get all student homework
	for k, v := range term_list {
		if term.Id != v.Id {
			term_list[k].Orgs = make(map[string]interface{})

			if s_courses, err := models.GetStudentCourseByTerm(term_list[k], this.Data["student"].(*models.Student).Id); err == nil {
				//	get the homework
				for k, v := range s_courses {
					if s_homeworks, err := models.GetStudentHomeworkByStudentCourse(v, this.Data["student"].(*models.Student).Id); err == nil {
						s_courses[k].Orgs = make(map[string]interface{})
						s_courses[k].Orgs["s_homeworks"] = s_homeworks
					} else {
						continue
					}
				}
				term_list[k].Orgs["s_course"] = s_courses
			}
		}
	}
	this.Data["term_list"] = models.RankingTerm(term_list)

	this.Layout = "student/base.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Head_html"] = "student/head/homework_head.html"
	this.LayoutSections["Scripts"] = "student/scripts/homework_scripts.html"
	this.TplNames = "student/homework.html"
}
Пример #5
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
}
Пример #6
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
}