예제 #1
0
class TecStartCheckInControl(object):
    # 实例考勤队列
    cia = CheckInArray()

    def __init__(self):
        self.seq = SeqInfo()
        self.detail = DetailInfo()
        self.course = CourseInfo()
        self.stu = StuInfo()
        self.sum = SumInfo()

    # 获取当前系统时间
    def get_time(self):
        """
        获取系统当前的时间
        :return: 
        """
        return time.strftime("%Y-%m-%d %X", time.localtime())

    # 初始化seq表
    def creat_seq(self, seq_filename):
        creat_seq_line = [{
            "TeacherID": None,
            "CourseID": None,
            "SeqID": None,
            "StartTime": None
        }]
        self.seq.write_file(creat_seq_line, seq_filename)

    # 更新seq表
    def update_seq(self, now_cii, seq_filename):
        # 获取seq表已有信息
        all_seq_info = self.seq.get_all_seq_info(seq_filename)
        # 分配新的考勤次序号
        seq_id = int(
            self.seq.get_seqid(now_cii.tecid, now_cii.courseid,
                               all_seq_info)) + 1
        now_cii.seqid = str(seq_id)
        # 构建新的考勤次序记录
        new_sql_line = self.seq.set_seq_line(now_cii.tecid, now_cii.courseid,
                                             now_cii.seqid, now_cii.starttime)
        # 将新的考勤记录加入seq表
        all_seq_info = self.seq.seq_update(new_sql_line, all_seq_info)
        # 更新seq表
        self.seq.write_file(all_seq_info, seq_filename)
        return

    # 初始化detail表
    def creat_detail(self, now_cii, default_path):
        # 构建detail文件名
        teacher_id = now_cii.tecid
        course_id = now_cii.courseid
        seq_id = now_cii.seqid
        new_detail_filename = default_path + self.detail.set_detail_filename(
            teacher_id, course_id, seq_id)
        # 待考勤学生id集合
        stuids = now_cii.stuids
        # 初始化detail表
        newdetail_info = []
        for stuid in stuids:
            newdetail_line = \
                self.detail.set_detail_line(stuid, self.get_time(),
                                            self.detail.set_proofpath(stuid, course_id, seq_id, self.get_time()),
                                            "man", "null", "in")
            newdetail_info.append(newdetail_line)
        self.detail.write_file(newdetail_info, new_detail_filename, "wb")

    # 初始化sum表本
    # 导入考勤结果

    # 教师发起自助考勤
    def tec_start_checkin(self, now_cii, seq_filename):
        # 考勤对象家加入考勤队列
        if self.__class__.cia.update_arry(now_cii):
            print "开启成功"
            # 初始化seq表
            # self.creat_seq(seq_filename)  # 有一次即可
            # 在seq表添加记录 !!!只有一行
            self.update_seq(now_cii, seq_filename)
            # 初始化detail表
            default_path = seq_filename[:-7]
            self.creat_detail(now_cii, default_path)
            # 初始化sum表 不应放在这里
        else:
            print "开启失败"

    # 学生签到(stu_id, proof)
    # 查找该学生所属的考勤对象
    def get_checkininfo(self, stu_id, stu_filename):
        # all_stu_info = self.stu.get_all_stu_info(stu_filename)
        # classname = self.stu.get_classid(stu_id, all_stu_info)
        for acia in self.__class__.cia.List:
            if stu_id in acia.stuids:
                return acia
        return

    # 构造detail_line信息
    def set_new_detail_line(self, stuid, acii, result="wait"):
        newdetail_line = \
            self.detail.set_detail_line(stuid, self.get_time(),
                                        self.detail.set_proofpath(stuid, acii.courseid, acii.seqid, self.get_time()),
                                        "auto", "null", result)
        return newdetail_line

    # 提交/请假(result="wait"/"qj")
    def stu_send_checkininfo(self, stuid, result, stu_filename, default_path):
        now_cii = self.get_checkininfo(stuid, stu_filename)  # 这里应当做考勤对象是否存在的判断
        new_detail_line = self.set_new_detail_line(stuid, now_cii, result)
        # 构建detail文件名
        teacher_id = now_cii.tecid
        course_id = now_cii.courseid
        seq_id = now_cii.seqid
        new_detail_filename = default_path + self.detail.set_detail_filename(
            teacher_id, course_id, seq_id)
        all_detail_info = self.detail.get_all_detail_info(new_detail_filename)
        all_detail_info.append(new_detail_line)
        self.detail.write_detail(all_detail_info, new_detail_filename)
예제 #2
0
class TecManCheckInInsertControl(object):
    def __init__(self):
        self.seq = SeqInfo()
        self.detail = DetailInfo()
        self.course = CourseInfo()
        self.stu = StuInfo()
        self.sum = SumInfo()

    # 获取当前系统时间
    def get_time(self):
        """
        获取系统当前的时间
        :return: 
        """
        return time.strftime("%Y-%m-%d %X", time.localtime())

    # 获取所有学生的名单
    def get_all_stuids(self, tec_id, course_id, course_filename, stu_filename):
        all_course_info = self.course.get_all_course_info(course_filename)
        classnums = self.course.get_classnames(tec_id, course_id,
                                               all_course_info)
        all_stu_info = self.stu.get_all_stu_info(stu_filename)
        stu_ids = self.stu.get_stuids(
            self.stu.get_wait_checkin_stu_info(classnums, all_stu_info))
        if stu_ids:
            return stu_ids
        else:
            return None

    # 教师手工修改
    def man_change(self, tec_id, course_id, seq_id, stu_id, result,
                   course_filename, stu_filename, seq_filename, default_path):
        # 检查seqid的有效性
        all_seq_info = self.seq.get_all_seq_info(seq_filename)
        new_seqid = self.seq.get_seqid(tec_id, course_id, all_seq_info)
        if int(seq_id) > 0 and int(seq_id) <= new_seqid:
            # 检查stuid的有效性
            all_stuids = self.get_all_stuids(tec_id, course_id,
                                             course_filename, stu_filename)
            if all_stuids and stu_id in all_stuids:
                # 构造detail行数据
                new_detail_info = [
                    self.detail.set_detail_line(stu_id, self.get_time(),
                                                "null", "man", "null", result)
                ]
                new_filename = self.detail.set_detail_filename(
                    tec_id, course_id, str(seq_id))
                new_filename = default_path + new_filename
                self.detail.write_file(new_detail_info, new_filename, 'ab')
            else:
                print "该学生非本班学生,请检查后重新操作"
        else:
            print "没有您选择的考勤序号,请检查后重新输入"

    # 教师手工考勤控制
    def man_checkin(self, tec_id, course_id, course_filename, stu_filename,
                    arrive, absence, late, early, note, seq_filename,
                    default_path):
        error_ids = self.check_stuids(
            arrive, absence, late, early, note,
            self.get_all_stuids(tec_id, course_id, course_filename,
                                stu_filename))
        if error_ids:
            print "部分名单非本班学生,请检查后重新操作,错误(stuid)名单:", error_ids
        else:
            # 构造手工考勤的detail信息
            new_detail_info = self.build_detail(arrive, absence, late, early,
                                                note)
            print "手工考勤记录完成"
            # 1.在seq表中增加记录
            seq_id = self.update_seq_info(tec_id, course_id, seq_filename)
            # 2.在detail表中保存记录
            self.update_detail_info(tec_id, course_id, seq_id, new_detail_info,
                                    default_path)

    # 1.在seq表中增加记录
    def update_seq_info(self, tec_id, course_id, seq_filename):
        all_seq_info = self.seq.get_all_seq_info(seq_filename)
        new_seqid = self.seq.get_seqid(tec_id, course_id, all_seq_info) + 1
        new_seq_line = self.seq.set_seq_line(tec_id, course_id, str(new_seqid),
                                             self.get_time())
        new_seq_info = [new_seq_line]
        self.seq.write_file(new_seq_info, seq_filename, 'ab')
        return new_seqid

    # 2.在detail表中保存记录
    def update_detail_info(self, tec_id, course_id, seq_id, detail_info,
                           default_path):
        new_filename = self.detail.set_detail_filename(tec_id, course_id,
                                                       str(seq_id))
        new_filename = default_path + new_filename
        self.detail.write_file(detail_info, new_filename, 'wb')

    # 检查教师输入的学生名单是否在该考勤对象中
    def check_stuids(self, arrive, absence, late, early, note, all_studis):
        # 验证输入的学生名单是否存在与考勤对象,不存在的打印提示错误。
        warning = []
        for a_person in arrive:
            if a_person in all_studis:
                pass
            else:
                warning.append(a_person)

        for a_person in absence:
            if a_person in all_studis:
                pass
            else:
                warning.append(a_person)

        for a_person in late:
            if a_person in all_studis:
                pass
            else:
                warning.append(a_person)

        for a_person in early:
            if a_person in all_studis:
                pass
            else:
                warning.append(a_person)

        for a_person in note:
            if a_person in all_studis:
                pass
            else:
                warning.append(a_person)
        # 若存在非考勤对象名单
        if warning:
            return warning
        else:
            return None

    # 为4中考勤结果的学生构造detail数据
    def build_detail(self, arrive, absence, late, early, note):
        new_detail_info = []
        for a_person in arrive:
            new_detail_info.append(
                self.detail.set_detail_line(a_person, self.get_time(), "null",
                                            "man", "null", "到勤"))

        for a_person in absence:
            new_detail_info.append(
                self.detail.set_detail_line(a_person, self.get_time(), "null",
                                            "man", "null", "缺勤"))

        for a_person in late:
            new_detail_info.append(
                self.detail.set_detail_line(a_person, self.get_time(), "null",
                                            "man", "null", "迟到"))

        for a_person in early:
            new_detail_info.append(
                self.detail.set_detail_line(a_person, self.get_time(), "null",
                                            "man", "null", "早退"))

        for a_person in note:
            new_detail_info.append(
                self.detail.set_detail_line(a_person, self.get_time(), "null",
                                            "man", "null", "请假"))

        return new_detail_info
예제 #3
0
class TecApproveNote(object):
    def __init__(self):
        self.course = CourseInfo()
        self.stu = StuInfo()
        self.seq = SeqInfo()
        self.detail = DetailInfo()

    # 审批假条
    def approve_note(self, tec_id, course_id, seq_id, stu_ids, seq_filename,
                     default_path):
        if self.check_seqid(tec_id, course_id, seq_id, seq_filename):
            if self.check_stuids(tec_id, course_id, seq_id, stu_ids,
                                 default_path):
                new_detail_info = self.build_detail(stu_ids)
                detail_filename = self.detail.set_detail_filename(
                    tec_id, course_id, str(seq_id))
                detail_filename = default_path + detail_filename
                self.update_detail(new_detail_info, detail_filename)
            else:
                print "有学生非本班学生,请检查后重新操作"
        else:
            print "没有您选择的考勤序号,请检查后重新输入"

    # 获取当前系统时间
    def get_time(self):
        """
        获取系统当前的时间
        :return: 
        """
        return time.strftime("%Y-%m-%d %X", time.localtime())

    # 1.检查seqid有效性
    def check_seqid(self, tec_id, course_id, seq_id, seq_filename):
        # 通过获取最大seqid值验证当前输入的seqid值是否有效
        all_seq_info = self.seq.get_all_seq_info(seq_filename)
        max_seqid = self.seq.get_seqid(tec_id, course_id, all_seq_info)
        if int(seq_id) > 0 and int(seq_id) <= int(max_seqid):
            return True
        else:
            return False

    # 检查输入的学生的有效性
    def check_stuids(self, tec_id, course_id, seq_id, stu_ids, default_path):
        # 通过获取该考勤对象的学生集合,判断输入的学号是否有效
        detail_filename = self.detail.set_detail_filename(
            tec_id, course_id, seq_id)
        detail_filename = default_path + detail_filename
        all_stuids = self.note_stu_ids(detail_filename)
        for a_stuid in stu_ids:
            if a_stuid in all_stuids:
                pass
            else:
                return False
        return True

    # 2.打印请假学生
    def show_note_stuids(self, tec_id, course_id, seq_id, seq_filename,
                         default_path):
        all_seq_info = self.seq.get_all_seq_info(seq_filename)
        max_seqid = self.seq.get_seqid(tec_id, course_id, all_seq_info)
        if int(seq_id) > 0 and int(seq_id) <= int(max_seqid):
            detail_filename = self.detail.set_detail_filename(
                tec_id, course_id, seq_id)
            detail_filename = default_path + detail_filename
            note_stuids = self.note_stu_ids(detail_filename)
            return note_stuids
        else:
            print "您输入选择的seqid错误,请检查后重新操作"

    # 请假学生
    def note_stu_ids(self, detail_filename):
        stuids = []
        all_detail_info = self.detail.get_all_detail_info(detail_filename)
        for a_detail_line in all_detail_info:
            if a_detail_line["CheckinResult"] == "请假":
                stuids.append(a_detail_line["StuID"])
            else:
                pass
        return stuids

    # 3.将审批通过的记录计入detail表
    def update_detail(self, new_detail_info, detail_filename):
        self.detail.write_file(new_detail_info, detail_filename, 'ab')

    # 构造detail数据
    def build_detail(self, stu_ids):
        new_detail_info = []
        for a_person in stu_ids:
            new_detail_info.append(
                self.detail.set_detail_line(a_person, self.get_time(), "null",
                                            "man", "null", "请假通过"))
        return new_detail_info