Пример #1
0
func getScheduleChildByChildIdAndScheduleId(childId, scheduleId string) (map[string]string, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select id,schedule_detail_id,child_id,create_user,wyclass_id,contract_id,is_free from schedule_detail_child where child_id=? and schedule_detail_id=? "
	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, childId, scheduleId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
		if err != nil {
			lessgo.Log.Error(err.Error())
			return nil, err
		}
	}

	return dataMap, nil
}
Пример #2
0
func getFurtherScheduleIds(timeId, roomId, week, startTime, courseId string) ([]string, error) {

	sql := `
			select id from class_schedule_detail where time_id=? and room_id=? and week=? and start_time>=? and course_id=?`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, timeId, roomId, week, startTime, courseId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	ids := []string{}

	for rows.Next() {
		id := ""
		err := commonlib.PutRecord(rows, &id)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return nil, err
		}

		ids = append(ids, id)
	}

	return ids, nil
}
Пример #3
0
/*
select csd.id,class_id classId,teacher_id teacherId,assistant_id assistantId,course_id courseId,center_id centerId,time_id timeId,room_id roomId,day_date dayDate,week,capacity,start_time startTime,end_time endTime,status,cour.name courseName,r.name roomName
			from class_schedule_detail csd
			left join course cour on cour.cid=csd.course_id
			left join room r on r.rid = csd.room_id
			where csd.id=?
*/
func getScheduleDetailId(id string) (map[string]string, error) {

	sql := `
			select csd.id,csd.class_id classId,csd.teacher_id teacherId,csd.assistant_id assistantId,csd.course_id courseId,csd.center_id centerId,csd.time_id timeId,csd.room_id roomId,csd.day_date dayDate,csd.week,csd.capacity,csd.start_time startTime,csd.end_time endTime,csd.status,cour.name courseName,r.name roomName
			from class_schedule_detail csd
			left join course cour on cour.cid=csd.course_id
			left join room r on r.rid = csd.room_id
			where csd.id=?
	    	`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
	}

	if err != nil {
		return nil, err
	}

	return dataMap, nil
}
Пример #4
0
func FindTimeSectionById(id string) (TimeSection, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select id,center_id,start_time,end_time,lesson_no from time_section where id=? "

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		return TimeSection{}, err
	}

	timeSection := TimeSection{}

	if rows.Next() {
		err = commonlib.PutRecord(rows, &timeSection.Id, &timeSection.CenterId, &timeSection.StartTime, &timeSection.EndTime, &timeSection.LessonNo)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			return TimeSection{}, err
		}
	}

	return timeSection, nil
}
Пример #5
0
func FindChildById(id string) (Child, error) {
	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select cid,name,card_id,pid,sex,birthday,hobby,center_id,avatar from child where cid=?"

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		return Child{}, err
	}

	child := Child{}

	if rows.Next() {
		err = commonlib.PutRecord(rows, &child.Cid, &child.Name, &child.CardId, &child.Pid, &child.Sex, &child.Birthday, &child.Hobby, &child.CenterId, &child.Avatar)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			return Child{}, err
		}
	}

	return child, nil
}
Пример #6
0
//根据id获取员工信息
func FindEmployeeById(id int) (Employee, error) {

	var employee Employee

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select user_id,username,really_name,department_id,center_id from employee where user_id=?"

	rows, err := db.Query(sql, id)
	if err != nil {
		lessgo.Log.Error(err.Error())
		return employee, err
	}

	if rows.Next() {
		err := commonlib.PutRecord(rows, &employee.UserId, &employee.UserName, &employee.ReallyName, &employee.DepartmentId, &employee.CenterId)
		if err != nil {
			lessgo.Log.Error(err.Error())
			return employee, err
		}
	}

	return employee, nil
}
Пример #7
0
func InsertCourse(centerId, courseName, courseType string) (flag bool, msg string, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	courseNameFlag, err := checkCourseNameExist(centerId, courseName)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	if !courseNameFlag {
		_, err = insertCourse(tx, centerId, courseName, courseType)
		if err != nil {
			lessgo.Log.Error(err.Error())
			return false, "", err
		}
	} else {
		return false, "课程名字已存在", nil
	}

	tx.Commit()

	return true, "", nil
}
Пример #8
0
func checkScheduleTempChildExist(childId, scheduleTempId string) (flag bool, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := " select count(1) from schedule_template_child where child_id=? and  schedule_template_id=? "

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, childId, scheduleTempId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, err
	}

	num := 0

	if rows.Next() {

		err = commonlib.PutRecord(rows, &num)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return false, err
		}
	}

	if num > 0 {
		return true, nil
	}

	return false, nil
}
Пример #9
0
/*
select st.id,st.room_id,st.time_id,st.week,csd.start_time,csd.course_id
			from class_schedule_detail csd
			left join schedule_template st on csd.center_id=st.center_id and csd.room_id=st.room_id and csd.time_id=st.time_id and csd.week=st.week
			where csd.id=?
*/
func getScheduleTmpByScheduelDetailId(scheduleId string) (map[string]string, error) {

	sql := `
			select st.id,st.room_id,st.time_id,st.week,csd.start_time,csd.course_id
			from class_schedule_detail csd
			left join schedule_template st on csd.center_id=st.center_id and csd.room_id=st.room_id and csd.time_id=st.time_id and csd.week=st.week
			where csd.id=?`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, scheduleId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
	}

	if err != nil {
		return nil, err
	}

	return dataMap, nil
}
Пример #10
0
func FindLessonById(id string) (Lesson, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select lid,course_id,caption,teacher_id,keystone,lesson_time,order_no,is_last from lesson where lid=? "

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		return Lesson{}, err
	}

	lesson := Lesson{}

	if rows.Next() {
		err = commonlib.PutRecord(rows, &lesson.Lid, &lesson.CourseId, &lesson.Caption, &lesson.TeacherId, &lesson.KeyStone, &lesson.LessonTime, &lesson.OrderNo, &lesson.IsLast)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			return Lesson{}, err
		}
	}

	return lesson, nil
}
Пример #11
0
func getTimeSectionById(id string) (map[string]string, error) {

	sql := `select id,center_id,start_time,end_time,lesson_no from time_section where id=?`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
	}

	if err != nil {
		return nil, err
	}

	return dataMap, nil
}
Пример #12
0
func FindClassById(id string) (WyClass, error) {
	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select wc.class_id,wc.assistant_id,wc.name,wc.course_id,wc.center_id,wc.child_num,wc.end_time,wc.deadline,wc.max_child_num,wc.teacher_id,c.is_probation from wyclass wc left join course c on wc.course_id=c.cid where wc.class_id=?"

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		return WyClass{}, err
	}

	class := WyClass{}

	if rows.Next() {
		err = commonlib.PutRecord(rows, &class.ClassId, &class.AssistantId, &class.Name, &class.CourseId, &class.CenterId, &class.ChildNum, &class.EndTime, &class.DeadLine, &class.MaxChildNum, &class.TeacherId, &class.IsProbation)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			return WyClass{}, err
		}
	}

	return class, nil
}
Пример #13
0
/*
select class_id id,name,start_time,end_time,code,center_id,child_num from wyclass where class_id=?
*/
func getWyClassById(id string) (map[string]string, error) {

	sql := `
			select class_id id,name,start_time,end_time,code,center_id,child_num from wyclass where class_id=?
	    	`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
	}

	if err != nil {
		return nil, err
	}

	return dataMap, nil
}
Пример #14
0
func getNewestFreeScheduleIdByChildId(childId string) (scheduleId, classId string, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select schedule_detail_id,wyclass_id from schedule_detail_child where child_id=? and is_free=1 order by id desc "
	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, childId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return "", "", err
	}

	if rows.Next() {
		err = commonlib.PutRecord(rows, &scheduleId, &classId)
		if err != nil {
			lessgo.Log.Error(err.Error())
			return "", "", err
		}
	}

	return scheduleId, classId, nil
}
Пример #15
0
/*
select id,child_id,apply_time,contract_no,parent_id,price,employee_id,center_id,course_id,left_lesson_num,type,status,expire_date from contract where id=?
*/
func getContractIdByChildIdAndScheduleId(childId, scheduleId string) (contractId, isFree string, err error) {

	sql := `select contract_id,is_free from schedule_detail_child where child_id=? and schedule_detail_id=?`
	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, childId, scheduleId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return "0", "", err
	}

	if rows.Next() {
		err = commonlib.PutRecord(rows, &contractId, &isFree)
	}

	if err != nil {
		lessgo.Log.Error(err.Error())
		return "0", "", err
	}

	return contractId, isFree, nil
}
Пример #16
0
func getScheduleTmpsByCenterId(centerId string) ([]map[string]string, error) {
	db := lessgo.GetMySQL()
	defer db.Close()

	getScheduleTmpSql := "select id,room_id,teacher_id,assistant_id,time_id,week,course_id from schedule_template where center_id=? "
	lessgo.Log.Debug(getScheduleTmpSql)

	rows, err := db.Query(getScheduleTmpSql, centerId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var datas []map[string]string

	for rows.Next() {
		dataMap, err := lessgo.GetDataMap(rows)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return nil, err
		}

		datas = append(datas, dataMap)
	}

	return datas, nil
}
Пример #17
0
/*
select id,child_id,apply_time,contract_no,parent_id,price,employee_id,center_id,course_id,left_lesson_num,type,status,expire_date from contract where id=?
*/
func getContractById(id string) (map[string]string, error) {

	sql := `select id,child_id,apply_time,contract_no,parent_id,price,employee_id,center_id,course_id,left_lesson_num,type,status,expire_date from contract where id=?`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
	}

	if err != nil {
		return nil, err
	}

	return dataMap, nil
}
Пример #18
0
func getChildAndContractByScheduleTempId(tempId string) ([]map[string]string, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select child_id,contract_id from schedule_template_child where schedule_template_id=? "
	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, tempId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var datas []map[string]string

	for rows.Next() {
		dataMap, err := lessgo.GetDataMap(rows)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return nil, err
		}

		datas = append(datas, dataMap)
	}

	return datas, nil
}
Пример #19
0
//保存通话记录备注
func AudioNoteSaveAction(w http.ResponseWriter, r *http.Request) {

	m := make(map[string]interface{})

	employee := lessgo.GetCurrentEmployee(r)

	if employee.UserId == "" {
		lessgo.Log.Warn("用户未登陆")
		m["success"] = false
		m["code"] = 100
		m["msg"] = "用户未登陆"
		commonlib.OutputJson(w, m, " ")
		return
	}

	err := r.ParseForm()

	if err != nil {
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	id := r.FormValue("aid")
	note := r.FormValue("note")

	sql := "update audio set note=? where aid=? "

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	stmt, err := db.Prepare(sql)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	_, err = stmt.Exec(note, id)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "出现错误,请联系IT部门,错误信息:" + err.Error()
		commonlib.OutputJson(w, m, " ")
		return
	}

	m["success"] = true
	commonlib.OutputJson(w, m, " ")
}
Пример #20
0
//todo 目前只返回第一个孩子的id,逻辑有待优化
func getChildByParentId(pid string) (int64, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select cid from child where pid=?"

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, pid)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return 0, err
	}

	var id int64

	if rows.Next() {

		err = commonlib.PutRecord(rows, &id)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return 0, err
		}
	}

	return id, nil
}
Пример #21
0
func UpdateCourse(id, courseName, courseType string) (flag bool, msg string, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	updateCourseMap := make(map[string]interface{})
	updateCourseMap["name"] = courseName
	updateCourseMap["type"] = courseType

	err = updateCourse(tx, updateCourseMap, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	tx.Commit()

	return true, "", nil
}
Пример #22
0
//todo 目前只返回第一个孩子的id,逻辑有待优化
func getChildByConsumerId(consumerId string) (int64, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select ch.cid from child ch left join consumer_new cons on cons.parent_id=ch.pid where cons.id=?"

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, consumerId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return 0, err
	}

	var id int64

	if rows.Next() {

		err = commonlib.PutRecord(rows, &id)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return 0, err
		}
	}

	return id, nil
}
Пример #23
0
//修改表单数据读取
func LoadCourseware(id string) (loadFormObjects []lessgo.LoadFormObject, err error) {
	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select id,name,intro from courseware where id=? "
	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, id)

	var name, intro string

	if rows.Next() {
		err := commonlib.PutRecord(rows, &id, &name, &intro)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			return nil, err
		}
	}

	h1 := lessgo.LoadFormObject{"id", id}
	h2 := lessgo.LoadFormObject{"name", name}
	h3 := lessgo.LoadFormObject{"intro", intro}

	loadFormObjects = append(loadFormObjects, h1)
	loadFormObjects = append(loadFormObjects, h2)
	loadFormObjects = append(loadFormObjects, h3)

	return loadFormObjects, nil
}
Пример #24
0
func ChildPay(childId, scheduleId, classId, payType, employeeId string) (flag bool, msg string, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	flag, msg, err = childPay(tx, childId, "", scheduleId, classId, payType, employeeId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	if !flag {
		return false, msg, nil
	}

	tx.Commit()

	return true, "", nil
}
Пример #25
0
func checkChildInSchedule(childId, scheduleId string) (bool, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select count(1) from schedule_detail_child where child_id=? and schedule_detail_id=? "

	rows, err := db.Query(sql, childId, scheduleId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, err
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return false, err
		}
	}

	if totalNum > 0 {
		return true, nil
	}

	return false, nil
}
Пример #26
0
/*
select cid id,name,card_id cardId,pid,sex,birthday,center_id centerId,avatar from child where cid=?
*/
func getChildById(id string) (map[string]string, error) {

	sql := `select cid id,name,card_id cardId,pid,sex,birthday,center_id centerId,avatar
	        from child where cid=?`

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return nil, err
	}

	var dataMap map[string]string

	if rows.Next() {
		dataMap, err = lessgo.GetDataMap(rows)
	}

	if err != nil {
		return nil, err
	}

	return dataMap, nil
}
Пример #27
0
func checkScheduleExist(centerId, roomId, timeId, dayDate string) (flag bool, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select id from class_schedule_detail where center_id=? and room_id=? and time_id=? and day_date=?"
	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, centerId, roomId, timeId, dayDate)
	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, err
	}

	scheduleDetailId := 0

	if rows.Next() {
		err = commonlib.PutRecord(rows, &scheduleDetailId)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return false, err
		}
	}

	if scheduleDetailId == 0 {
		return false, nil
	}

	return true, nil
}
Пример #28
0
//获取指定合同的有效上课次数,这里的有效指的是正常上课和旷课
func getVaildNumOfContract(id string) (int, error) {

	sql := `select count(1) from sign_in where contract_id=? and (type=1 or type=3) `

	lessgo.Log.Debug(sql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(sql, id)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return 0, err
	}

	num := 0

	if rows.Next() {
		err = commonlib.PutRecord(rows, &num)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return 0, err
		}
	}

	return num, nil
}
Пример #29
0
func AddChildForNormalOnce(childId, scheduleId, contractId, employeeId string) (flag bool, msg string, err error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	tx, err := db.Begin()

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	childScheduleFlag, err := checkChildInSchedule(childId, scheduleId)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return false, "", err
	}

	if !childScheduleFlag {
		err = insertScheduleChild(tx, childId, scheduleId, "", employeeId, contractId, IS_FREE_NO)
		if err != nil {
			lessgo.Log.Error(err.Error())
			return false, "", err
		}
	}

	tx.Commit()

	return true, "", nil
}
Пример #30
0
//根据电话获取parent表的id
func getParentIdByPhone(phone string) (int64, error) {

	db := lessgo.GetMySQL()
	defer db.Close()

	sql := "select pid from parent where telephone=?"

	lessgo.Log.Debug(sql)

	rows, err := db.Query(sql, phone)

	if err != nil {
		lessgo.Log.Error(err.Error())
		return 0, err
	}

	var id int64

	if rows.Next() {

		err = commonlib.PutRecord(rows, &id)

		if err != nil {
			lessgo.Log.Error(err.Error())
			return 0, err
		}
	}

	return id, nil
}