def _check_student_relative(self, student_relative_info): name = student_relative_info.get('name', '') birthday = student_relative_info.get('birthday', '') class_id = student_relative_info.get('class_id', '') relative_list = student_relative_info.get("relative_list", []) if birthday and not convert.is_date(birthday): return 1, '%s: student info error.'%name if not name or not class_id: return 1, '%s: student info error.'%name relative_op = RelativeLogic() for relative_info in relative_list: relative_birthday = relative_info.get("birthday", "") if relative_birthday and not convert.is_date(convert.bs2utf8(relative_birthday)): return 2, '%s: relative info error.' % relative_info.get("name", "") phone = convert.bs2utf8(relative_info.get("phone", "")) if phone and not convert.is_mobile(phone): return 2, '%s: relative info error.' % relative_info.get("name", "") name = convert.bs2utf8(relative_info.get("name", "")) if not name: return 2, '%s: relative info error.' % relative_info.get("name", "") if phone: db_relative_list = relative_op.info_by_phone(phone=phone) if db_relative_list and convert.bs2utf8(db_relative_list[0].get("name", "")) != name: LOG.info("relative info, phone:%s and name:%s error"%(phone, name)) return 2, '%s: relative info error.' % relative_info.get("name", "") return 0, 'relative ok'
def com_sign(self, teacher_id, sign_date=""): """ 统计亲属签到信息 :param teacher_id: 教师编号 :return: """ sign_date = datetime.datetime.strptime( sign_date, "%Y-%m-%d") if convert.is_date( sign_date) else datetime.datetime.now() firstDay, lastDay = convert.getMonthFirstDayAndLastDay( sign_date.year, sign_date.month) sign_count = 0 # 出勤 late_count = 0 # 早上迟到 early_count = 0 # 下午早退 sign_status_list = db_api.teacher_sign_status_list( firstDay, lastDay, teacher_id=teacher_id) for status_info in sign_status_list: if status_info.status == "11": sign_count += 1 if status_info.status[0] == "2": late_count += 1 if status_info.status[1] == "2": early_count += 1 return sign_count, late_count, early_count, sign_date
def input(self, name="", sex=0, birthday="", class_id="", status="apply", relation_number=3, describe=""): if birthday and not convert.is_date(birthday): raise exception.FormalError(birthday=birthday) if not name: raise exception.ParamNone(name="") if not class_id: raise exception.ParamNone(name="") class_info = db_api.class_get(id=class_id) if not class_info: raise exception.NotFound(code=class_id) values = { "name": name, "sex": sex, #"birthday": birthday, "school_id": class_info.school_id, "grade_id": class_info.grade_id, "class_id": class_id, "describe": describe, #"status": status, "relation_number": relation_number } if birthday: values.update({"birthday": birthday}) student_obj = db_api.student_create(values) if student_obj: history_values={ "student_id": student_obj.get("id"), "staus": status } db_api.student_history_create(history_values) student_obj.update({"status": status}) return student_obj
def com_sign_detail(self, teacher_id, start_date="", end_date=""): """ :param teacher_id: :param start_date: :param end_date: :return: """ if not convert.is_date(start_date) or not convert.is_date(end_date): start_date, end_date = convert.getMonthFirstDayAndLastDay( datetime.datetime.now().year, datetime.datetime.now().month) else: start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d") start_date = datetime.date(start_date.year, start_date.month, start_date.day) end_date = datetime.strptime(end_date, "%Y-%m-%d") end_date = datetime.date(end_date.year, end_date.month, end_date.day) sign_status_list = db_api.teacher_sign_status_list( start_date, end_date, teacher_id=teacher_id) return sign_status_list
def com_sign_detail(self, student_id, start_date="", end_date=""): """ :param relation_list: :param start_date: :param end_date: :return: {"2018-12-01": "11"} """ if not convert.is_date(start_date) or not convert.is_date(end_date): start_date, end_date = convert.getMonthFirstDayAndLastDay(datetime.now().year, datetime.now().month) else: start_date = datetime.strptime(start_date, "%Y-%m-%d") start_date = date(start_date.year, start_date.month, start_date.day) end_date = datetime.strptime(end_date, "%Y-%m-%d") end_date = date(end_date.year, end_date.month, end_date.day) LOG.info("sign start end:%r, %r"%(start_date, end_date)) #result={} sign_status_list = db_api.student_sign_status_list(start_date, end_date, student_id=student_id) # for sign_status in sign_status_list: # result.update({datetime.strftime(sign_status.sign_date, "%Y-%m-%d"): sign_status.status}) return sign_status_list
def input(self, name="", sex=0, birthday="", school_id="", class_id="", phone="", position=2, describe="", status="education"): if birthday and not convert.is_date(birthday): raise exception.FormalError(birthday=birthday) if not name: raise exception.ParamNone(name="") if phone: _count = db_api.teacher_count(phone=phone) if _count > 0: raise exception.ParamExist(phone=phone) values = { "name": name, "sex": sex, #"birthday": birthday, "school_id": school_id, "phone": phone, "describe": describe, "status": status } if class_id: class_info = db_api.class_get(id=class_id) if class_info: values.update({ "school_id": class_info.school_id, "grade_id": class_info.grade_id, "class_id": class_id, }) if birthday: values.update({"birthday": birthday}) if position != 0: values.update({"position": position}) teacher_obj = db_api.teacher_create(values) if teacher_obj: history_values = { "teacher_id": teacher_obj.get("id"), "status": status } db_api.teacher_history_create(history_values) #teacher_obj.update({"status": status}) return teacher_obj
def infos_for_sign_day(self, id="", name="", school_id="", grade_id="", class_id="", relative_id="", sign_date="", limit=100, offset=1): offset = (offset - 1) * limit if offset > 0 else 0 filters = dict() if id: filters.update({"id": id}) if name: filters.update({"name": name}) if school_id: filters.update({"school_id": school_id}) if grade_id: filters.update({"grade_id": grade_id}) if class_id: filters.update({"class_id": class_id}) if relative_id: _relation_list = self._get_relations_by_relative(relative_id) if _relation_list: _ids = [_relation.student_id for _relation in _relation_list] filters.update({"id": _ids}) student_list = db_api.student_list(offset=offset, limit=limit, **filters) student_count = db_api.student_count(**filters) # 关联学校和班级,还有学生得签到(学生亲属的签到信息) views_list = self.views(student_list) for view in views_list: school_info = db_api.school_get(id=view.get("school_id")) if school_info: view.update({"school_name": school_info.name}) grade_info = view.get("grade_info", None) if grade_info: view.update({"grade_name": grade_info.get("name")}) class_info = view.get("class_info", None) if class_info: view.update({"class_name": class_info.get("name")}) sign_date = datetime.strptime(sign_date, "%Y-%m-%d") if convert.is_date(sign_date) else date.today() sign_status_list = db_api.student_sign_status_list(sign_date, sign_date, student_id=view.get("id")) if sign_status_list: view.update({ "sign_date": datetime.strftime(sign_date, "%Y-%m-%d"), "morning": sign_status_list[0].morning if sign_status_list[0].morning else "", "afternoon": sign_status_list[0].afternoon if sign_status_list[0].afternoon else "" }) return {"count": student_count, "state": 0, "message": "query success", "data": views_list}
def input(self, name="", sex=0, birthday="", phone="", describe=""): if birthday and not convert.is_date(birthday): raise exception.FormalError(birthday=birthday) if phone and not convert.is_mobile(phone): raise exception.FormalError(phone=phone) if not name: raise exception.ParamNone(name=convert.bs2unicode(name)) if phone: relative_list = db_api.relative_list(phone=phone) if relative_list and convert.bs2utf8( relative_list[0].name) != name: raise exception.ParamExist(name=name, phone=phone) values = {"name": name, "sex": sex, "describe": describe} if phone: values.update({"phone": phone}) if birthday: values.update({"birthday": birthday}) relativel_obj = db_api.relative_create(values) return relativel_obj