Пример #1
0
 def __init__(self):
     self.judgeData = JudgeData()  # 实例化
     self.spersonal = SPersonal()
     self.sstudent = SStudents()
     self.steacher = STeachers()
     self.suser = SUsers()
     self.scompetitions = SCompetitions()
Пример #2
0
 def __init__(self):
     self.steams = STeams()
     self.judgeData = JudgeData()  #实例化
     self.spersonal = SPersonal()
     self.sinfor = SInfor()
     self.sstudent = SStudents()
     self.steacher = STeachers()
     self.scompetitions = SCompetitions()
     self.suser = SUsers()
     if self.sinfor.status or self.sstudent.status or self.steacher.status or \
             self.scompetitions.status or self.suser.status:
         self.status = True
     else:
         self.status = False
Пример #3
0
 def __init__(self):
     self.student = SStudents()
     self.teacher = STeachers()
     self.personal = SPersonal()
     self.competition = SCompetitions()
     self.user = SUsers()
     self.team = STeams()
     self.infor = SInfor()
Пример #4
0
 def __init__(self):
     self.judgeData = JudgeData()
     self.steachers = STeachers()  # 实例化
Пример #5
0
class CTeachers():
    def __init__(self):
        self.judgeData = JudgeData()
        self.steachers = STeachers()  # 实例化

    def teachers_list(self):
        """
        获取所有教师的简略信息
        :return: 所有教师简略信息的list
        """
        if not self.steachers.status:
            return system_error
        args = request.args.to_dict()
        from models.model import Teachers
        # 判断是否含有参数
        try:
            # 参数成对存在,判断是否缺失,并判断具体内容是否合法,非法或为空均返回具体错误
            page_num, page_size = self.judgeData.check_page_params(args)
            params = []
            if "Ttime" in args:
                params.append(Teachers.Ttime == args.get("Ttime"))
            if "Tname" in args:
                name = get_str(args, "Tname")
                params.append(Teachers.Tname.like("%{0}%".format(name)))
            if "Tschool" in args:
                school = get_str(args, "Tschool")
                params.append(Teachers.Tschool.like("%{0}%".format(school)))

            page_num, count = JudgeData.check_page_value(
                page_num, page_size, "Teachers", params)
            start_num = (page_num - 1) * page_size
            search_teachers_list_success[
                "teacher_list"] = self.get_teachers_list(
                    start_num, page_size, params)
            search_teachers_list_success["count"] = count
            search_teachers_list_success["page_num"] = page_num
            return search_teachers_list_success
        except ParamsNotExitError as e:
            print e.message
            return param_miss
        except ValueError as e:
            print e.message
            return param_notright
        except Exception as e:
            print e.message
            return system_error

    def teachers_abo(self):
        """
        通过Tid来获取教师的详细信息,包括带队经历
        必须有参数Tid
        :return:
        """
        if not self.steachers.status:
            return system_error
        args = request.args.to_dict()
        # 判断是否含有参数并 校验参数中是否存在Tid,如果没有,抛出异常
        if not args or not self.judgeData.inData("Tid", args):
            return param_miss

        try:
            tid = args["Tid"]  # 获取Tid
            # 获取教师的所有基础信息
            teacher_abo = get_model_return_list(
                self.steachers.get_teacher_abo_by_tid(tid))
            # 获取教师的所有竞赛信息
            teacher_use = get_model_return_list(
                self.steachers.get_teacher_use_by_tid(tid))
            # 将竞赛信息拼装进教师基础信息中
            teacher_abo[0]["TCuse"] = teacher_use
            search_teachers_abo_success["teacher_abo"] = teacher_abo
            return search_teachers_abo_success
        except Exception as e:
            # 防止系统的莫名错误
            print e.message
            return system_error

    def get_teachers_list(self, start_num, page_size, params):
        """
        获取数据中所有教师内容
        :param start_num: 分页查询的页数
        :param page_size: 分页查询的每页记录数
        :param params 筛选条件 后端根据请求下发参数自动生成
        :return:teachers_list type is list default []
        """

        teachers_list = self.steachers.get_teachers_list(
            start_num, page_size, params)
        # [teachers_list1, 2, 3...]
        if isinstance(teachers_list, list) and teachers_list:
            return get_model_return_list(teachers_list)
        else:
            return []
Пример #6
0
class CTeams():
    def __init__(self):
        self.steams = STeams()
        self.judgeData = JudgeData()  #实例化
        self.spersonal = SPersonal()
        self.sinfor = SInfor()
        self.sstudent = SStudents()
        self.steacher = STeachers()
        self.scompetitions = SCompetitions()
        self.suser = SUsers()
        if self.sinfor.status or self.sstudent.status or self.steacher.status or \
                self.scompetitions.status or self.suser.status:
            self.status = True
        else:
            self.status = False

    # 展现团队列表,场景应用于团队信息和个人团队信息,没有校检
    def teams_list(self):
        if not self.steams.status:  # 校验数据库是否连接异常
            return system_error
        args = request.args.to_dict()

        # 判断是否含有参数
        try:
            params_Te = set()
            params_C = set()
            params_T = set()
            # 参数成对存在,判断是否缺失,并判断具体内容是否合法,非法或为空均报错
            page_num, page_size = self.judgeData.check_page_params(args)
            from models.model import Teams, Competitions, Teachers
            if "Tname" in args:
                params_Te.add(
                    Teams.TEname.like("%{0}%".format(get_str(args, "TEname"))))
            if "Cname" in args:
                params_C.add(
                    Competitions.Cname.like("%{0}%".format(
                        get_str(args, "Cname"))))
            if "Cno" in args:
                params_C.add(Competitions.Cno == args.get("Cno"))
            if "Clevel" in args:
                params_C.add(Competitions.Clevel == args.get("Clevel"))
            if "TEteachername" in args:
                params_T.add(
                    Teachers.Tname.like("%{0}%".format(
                        get_str("TEteachername", args))))

            team_list_data = self.steams.get_all_teams(
                params_Te)  # 第一层筛选 通过团队名称来筛选
            result_of_team_list = []
            for row in team_list_data:
                result_of_team_item = {}
                result_of_team_item["TEid"] = row.TEid
                result_of_team_item["TEname"] = row.TEname
                tenum = row.TEnum
                tenum_now = self.steams.get_count_by_teid(row.TEid)
                # 第二层筛选,通过isFUll筛选
                if "isFull" in args and bool(args.get("isFull")) != bool(
                        tenum_now in range(0, tenum + 1)):
                    continue

                result_of_team_item["isFull"] = 0 if bool(
                    tenum_now in range(0, tenum + 1)) else 1
                competitions_item = self.steams.get_cname_cno_clevel_by_cid(
                    row.Cid, params_C)
                # 第三层筛选,通过竞赛相关的三个筛选条件筛选
                if not competitions_item:
                    continue

                result_of_team_item["Cname"] = competitions_item.Cname
                result_of_team_item["Cno"] = competitions_item.Cno
                result_of_team_item["Clevel"] = competitions_item.Clevel
                leader_id = self.steams.get_sid_by_teid(row.TEid)
                # 第四层筛选, 通过团队leader筛选
                if "TEleader" in args and args.get(
                        "TEleader") not in self.sstudent.get_sname_by_sid(
                            leader_id):
                    continue

                result_of_team_item[
                    "TEleader"] = self.sstudent.get_sname_by_sid(leader_id)
                teacher_id = self.steams.get_tid_by_teid(row.TEid)
                params_T.add(Teachers.Tid == teacher_id)
                # 第5层筛选,通过教师名称来筛选
                if not self.steacher.get_tname_by_tid(params_T):
                    continue
                result_of_team_item[
                    "TEteachername"] = self.steacher.get_tname_by_tid(params_T)

                result_of_team_list.append(result_of_team_item)
            result_response = {}
            result_response["status"] = 200
            result_response["messages"] = ""
            result_response["team_list"] = result_of_team_list
            return result_response

        except (ParamsNotExitError) as e:
            print e.message
            return param_miss
        except ValueError as e:
            print e.message
            # return param_notright.fromkeys(e.message)
        except Exception as e:
            print e.message
            return system_error

    # 团队信息详情,根据团队唯一ID进行检索,目前写的非常粗糙,没有进行权限的校检,也没有进行数据的校检,单纯算是完成了正向逻辑
    def team_abo(self):
        if not self.steams.status:  # 校验数据库是否连接异常
            return system_error
        args = request.args.to_dict()

        if "TEid" not in args or "Uid" not in args:
            return param_miss
        teid = get_str(args, "TEid")
        uid = get_str(args, "Uid")
        utype = self.suser.get_utype_by_uid(uid)
        in_team = True

        result_of_team_abo = {}
        result_of_team_student_list = []

        team_abo = self.steams.get_team_abo_by_teid(teid)
        result_of_team_abo["TEid"] = team_abo.TEid
        result_of_team_abo["TEname"] = team_abo.TEname
        result_of_team_abo["TEnum"] = team_abo.TEnum
        cid = team_abo.Cid
        competition_abo = self.scompetitions.get_competitions_abo_by_cid(cid)
        result_of_team_abo["Cname"] = competition_abo[0].Cname
        result_of_team_abo["Cno"] = competition_abo[0].Cno
        result_of_team_abo["Clevel"] = competition_abo[0].Clevel
        result_of_team_abo["Cabo"] = competition_abo[0].Cabo
        leader_id = self.steams.get_sid_by_teid(teid)
        result_of_team_abo["TEleader"] = self.sstudent.get_sname_by_sid(
            leader_id)
        teacher_id = self.steams.get_tid_by_teid(teid)
        result_of_team_abo["Teachername"] = self.steacher.get_tname_by_tid(
            teacher_id)
        wait_num, refuse_num = self.steams.get_count_wait_refuse_by_teid(teid)
        result_of_team_abo["Wait"] = wait_num
        result_of_team_abo["Refuse"] = refuse_num
        team_student = self.steams.get_student_list_by_teid(teid)
        for row in team_student:
            result_of_team_student_item = {}
            result_of_team_student_item["Sid"] = row.Sid
            result_of_team_student_item["TStype"] = row.TStype
            result_of_team_student_item[
                "Sname"] = self.sstudent.get_sname_by_sid(row.Sid)
            result_of_team_student_list.append(result_of_team_student_item)
        result_of_team_abo["student_list"] = result_of_team_student_list
        result_response = {}
        result_response["status"] = 200
        result_response["messages"] = ""
        result_response["team_abo"] = result_of_team_abo

        return result_response

    # 个人的团队
    def myteams(self):
        if not self.steams.status:  # 校验数据库是否连接异常
            return system_error
        args = request.args.to_dict()
        print args

        if not self.judgeData.inData("Uid", args) or not self.judgeData.inData(
                "is_index", args):
            return param_miss

        uid = args["Uid"]
        is_index = args["is_index"]

        sid = self.sstudent.get_sid_by_uid(uid)
        team_list = []
        print is_index
        if int(is_index) == 0000:
            print 1
            team_list_abo = self.steams.get_my_team(sid)
            for row in team_list_abo:
                print row
                team_list_item = {}
                team_list_item["TEid"] = row
                team_list_item["TEname"] = self.steams.get_tename_by_teid(row)
                cid = self.steams.get_cid_by_teid(row)
                cname_clevel_cno = self.scompetitions.get_competitions_name_level_no_by_cid(
                    cid)
                team_list_item["Cname"] = cname_clevel_cno.Cname
                team_list_item["Cno"] = cname_clevel_cno.Cno
                team_list_item["Clevel"] = cname_clevel_cno.Clevel
                team_list.append(team_list_item)
            return team_list
        elif int(is_index) == 1111:
            team_list_abo = self.steams.get_my_own_team(sid)
            for row in team_list_abo:
                team_list_item = {}
                team_list_item["TEid"] = row
                team_list_item["TEname"] = self.steams.get_tename_by_teid(row)
                cid = self.steams.get_cid_by_teid(row)
                cname_clevel_cno = self.scompetitions.get_competitions_name_level_no_by_cid(
                    cid)
                team_list_item["Cname"] = cname_clevel_cno.Cname
                team_list_item["Cno"] = cname_clevel_cno.Cno
                team_list_item["Clevel"] = cname_clevel_cno.Clevel
                team_list.append(team_list_item)
            return team_list
        else:
            print 1
            return param_miss

    # 新建团队(创建团队信息表和团队学生表的主要人员),入口在竞赛信息和团队板块的创建团队
    def new_team(self):
        add_status = True
        if not self.status:
            return system_error
        args = request.args.to_dict()  # 获取参数
        print args

        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]

        data = request.data  # 获取body体
        data = json.loads(data)
        print data
        # 判断body体中含有必要参数
        if not self.judgeData.inData("TEname", data) or not self.judgeData.inData("Cname", data) \
            or not self.judgeData.inData("TEnum", data) or not self.judgeData.inData("Cno", data) \
                or not self.judgeData.inData("Clevel", data):
            return param_miss

        cname = data["Cname"]
        cno = data["Cno"]
        clevel = data["Clevel"]

        cid = self.scompetitions.get_cid_by_cname_cno_clevel(
            cname, cno, clevel)
        tename = data["TEname"]
        tenum = data["TEnum"]
        teid = uuid.uuid4()

        # 创建团队信息
        add_team = self.steams.add_team(teid, tename, cid, 701, tenum)
        if not add_team and add_status:
            add_status = False

        sid = self.sstudent.get_sid_by_uid(uid)
        # 写入团队创始人信息
        add_team_student = self.steams.add_student_in_team(
            uuid.uuid4(), teid, sid, 1000, 1101)
        if not add_team_student and add_status:
            add_status = False

        # 如果data中含有students的信息,那么写入团队成员信息,这个函数重构
        if self.judgeData.inData("Students", data):
            for row in data["Students"]:
                if not self.judgeData.inData("Sno",
                                             row) or not self.judgeData.inData(
                                                 "Suniversity", row):
                    return param_miss
                else:
                    sid = self.sstudent.get_sid_by_sno_suniversity(
                        row["Sno"], row["Suniversity"])
                    add_team_student_list = self.steams.add_student_in_team(
                        uuid.uuid4(), teid, sid, 1002, 1100)
                    if not add_team_student_list and add_status:
                        add_status = False
                    uid2 = self.sstudent.get_uid_by_sid(
                        sid)  # 根据students中所有的sid来获取
                    add_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                      NEW_INVITATION, 1200,
                                                      901, cid, teid,
                                                      uid2)  # 这里需要判断一下分步异常的问题
                    if not add_infor and add_status:
                        add_status = False

        if self.judgeData.inData("Teachers", data):
            for row in data["Teachers"]:
                if not self.judgeData.inData("Tno",
                                             row) or not self.judgeData.inData(
                                                 "Tuniversity", row):
                    return param_miss
                else:
                    tid = self.steacher.get_tid_by_tno_tuniversity(
                        row["Tno"], row["Tuniversity"])
                    add_team_teacher_list = self.steams.add_teacher_in_team(
                        uuid.uuid4(), teid, tid, 1100)
                    if not add_team_teacher_list and add_status:
                        add_status = False
                    uid2 = self.steacher.get_uid_by_tid(tid)
                    add_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                      NEW_INVITATION, 1200,
                                                      901, cid, teid,
                                                      uid2)  # 这里需要判断一下分步异常的问题
                    if not add_infor and add_status:
                        add_status = False
        if not add_status:
            return system_error  # 应返回写入数据库异常
        return new_team_success

    # 更新团队信息,入口在团队信息详情,可更新数据不包含竞赛信息的大部分内容,如更新竞赛信息,只能更新竞赛的等级
    def update_team(self):
        if not self.status:
            return system_error
        update_team_item = {}  # 新建空的json变量

        args = request.args.to_dict()  # 获取参数
        print args
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]
        sid = self.sstudent.get_sid_by_uid(uid)  # 获取sid

        data = request.data  # 获取body体
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("TEname", data) or not self.judgeData.inData("Cname", data) \
            or not self.judgeData.inData("TEnum", data) or not self.judgeData.inData("Cno", data) \
                or not self.judgeData.inData("Clevel", data) or not self.judgeData.inData("TEid", data):
            return param_miss

        cid = self.scompetitions.get_cid_by_cname_cno_clevel(
            data["Cname"], data["Cno"], data["Clevel"])
        teid = data["TEid"]
        tstype = self.steams.get_tstype_by_teid_sid(teid, sid)  # 获取成员身份判断权限

        # 不是团队创建者或管理员,提醒没有权限
        if tstype != 1000 and tstype != 1001:
            return none_permissions

        # 如果具有权限,继续执行
        update_team_item["TEid"] = data["TEid"]
        update_team_item["TEname"] = data["TEname"]
        update_team_item["Cid"] = cid
        update_team_item["TEuse"] = 701  # 被废弃的团队是不可修改的,所以可修改的状态默认为701
        update_team_item["TEnum"] = data["TEnum"]
        # 更新团队表
        response_of_update = self.steams.update_teams_by_teid(
            teid, update_team_item)

        if not response_of_update:
            return system_error
        return update_team_success

    # 邀请学生加入团队,入口在学生信息和团队详情中
    def add_student(self):
        add_status = True
        if not self.status:
            return system_error
        args = request.args.to_dict()  # 获取参数
        print args

        # 判断参数中含有Uid和TEid
        if not self.judgeData.inData(
                "TEid", args) or not self.judgeData.inData("Uid", args):
            return param_miss

        teid = args["TEid"]
        uid = args["Uid"]

        data = request.data  # 获取body体
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("Sno", data) or not self.judgeData.inData(
                "Suniversity", data):
            return param_miss

        sno = data["Sno"]
        suniversity = data["Suniversity"]
        sid = self.sstudent.get_sid_by_sno_suniversity(sno, suniversity)
        no_student = {}
        no_student["status"] = 405
        no_student["status_code"] = 405301
        no_student[
            "messages"] = "please make sure the no or the university is true"
        if not sid:
            return no_student
        sid_list = self.steams.get_sid_list_by_teid(teid)
        if sid in sid_list:
            return have_invate_this_users
        cid = self.steams.get_cid_by_teid(teid)
        uid2 = self.sstudent.get_uid_by_sid(sid)

        # 创建学生团队关联,创建通知信息
        response_of_student_and_team = self.steams.add_student_in_team(
            uuid.uuid4(), teid, sid, 1002, 1100)
        if not response_of_student_and_team and add_status:
            add_status = False

        response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                  NEW_INVITATION, 1200, 901,
                                                  cid, teid, uid2)
        if not response_of_infor and add_status:
            add_status = False

        if not add_status:
            return system_error
        return invent_success

    # 申请加入团队
    def invate_add_team(self):
        add_status = True
        if not self.status:
            return system_error
        args = request.args.to_dict()  # 获取参数
        print args

        # 判断参数中含有Uid和TEid
        if not self.judgeData.inData("Uid", args):
            return param_miss
        uid = args["Uid"]

        data = request.data  # 获取body体
        data = json.loads(data)
        if not self.judgeData.inData("TEid", data):
            return param_miss
        teid = data["TEid"]

        sid = self.sstudent.get_sid_by_uid(uid)
        sid_list = self.steams.get_sid_list_by_teid(teid)
        if sid in sid_list:
            return have_invate_this_users
        cid = self.steams.get_cid_by_teid(teid)

        leader_sid = self.steams.get_sid_by_teid(teid)
        uid2 = self.sstudent.get_uid_by_sid(leader_sid)

        response_of_student_and_team = self.steams.add_student_in_team(
            uuid.uuid4(), teid, sid, 1002, 1100)
        if not response_of_student_and_team and add_status:
            add_status = False

        response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                  NEW_REQUEST, 1200, 905, cid,
                                                  teid, uid2)
        if not response_of_infor and add_status:
            add_status = False

        if not add_status:
            return system_error
        return invent_success

    # 邀请教师,入口在教师信息和团队详情中
    def add_teacher(self):
        add_status = True
        args = request.args.to_dict()  # 获取参数
        print args
        # 判断参数中含有Uid
        if not self.judgeData.inData(
                "TEid", args) or not self.judgeData.inData("Uid", args):
            return param_miss

        teid = args["TEid"]
        uid = args["Uid"]

        data = request.data  # 获取body体
        data = json.loads(data)
        # 判断body体中含有必要参数
        if not self.judgeData.inData("Tno", data) or not self.judgeData.inData(
                "Tuniversity", data):
            return param_miss

        tno = data["Tno"]
        tuniversity = data["Tuniversity"]
        tid = self.steacher.get_tid_by_tno_tuniversity(tno, tuniversity)
        tid_list = self.steams.get_tid_list_by_teid(teid)
        if tid in tid_list:
            return have_invate_this_users
        uid2 = self.steacher.get_uid_by_tid(tid)
        cid = self.steams.get_cid_by_teid(teid)

        # 创建教师团队关联,创建通知信息
        response_of_student_and_team = self.steams.add_teacher_in_team(
            uuid.uuid4(), teid, tid, 1100)
        if not response_of_student_and_team and add_status:
            add_status = False
        response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                  NEW_INVITATION, 1200, 901,
                                                  cid, teid, uid2)
        if not response_of_infor and add_status:
            add_status = False

        if not add_status:
            return system_error
        return invent_success

    # 学生同意加入、通过学生申请,入口在我的信息中, 目前只完成了学生同意加入部分
    def sub_student(self):
        update_tstudent_item = {}  # 新建空的json变量,放置TSid和TSsubject
        add_status = True
        args = request.args.to_dict()  # 获取参数
        print args
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args) or not self.judgeData.inData(
                "sub_index", args):
            return param_miss

        uid = args["Uid"]  # 这里的Uid一定是接收者
        sub_index = int(args["sub_index"])  # 这里标记的是同意&拒绝,1101通过,1102拒绝

        data = request.data  # 获取body体
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("Pid", data):
            return param_miss

        pid = data[
            "Pid"]  # 这里获取到消息的id,消息id中根据ptype901邀请905申请来判断,无论申请还是邀请,修改的都是当前Uid在Team中的关联关系
        teid = self.sinfor.get_teid_by_pid(pid)
        sid = self.sstudent.get_sid_by_uid(uid)
        tsid = self.steams.get_tsid_by_teid_sid(teid, sid)
        if sub_index == 1102:
            update_tstudent_item["TSid"] = tsid
            update_tstudent_item["Sid"] = sid
            update_tstudent_item["TEid"] = teid
            update_tstudent_item["TStype"] = 1002
            update_tstudent_item["TSsubject"] = 1102

            response_of_update_tstudent = self.steams.update_tstudent_by_tsid(
                tsid, update_tstudent_item)
            if not response_of_update_tstudent and add_status:
                add_status = False

            sname = self.sstudent.get_sname_by_sid(sid)
            tename = self.steams.get_tename_by_teid(teid)
            message = REFUSE_JOIN_TEAM.format(sname, tename)  # 信息报文
            uid2 = self.sinfor.get_uid2_by_pid(pid)
            response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                      message, 1200, 903, None,
                                                      teid, uid2)
            if not response_of_update_tstudent and add_status:
                add_status = False

            if not add_status:
                return system_error
            return refuse_join_team_success
        elif sub_index == 1101:
            # 根据团队id获取当前团队成员的数量,与团队最大数量进行对比,超过则显示满员
            # 这里需要对teid进行防sql注入处理
            students_num = self.steams.get_count_by_teid(teid)
            tenum = self.steams.get_tenum_by_teid(teid)

            if students_num >= tenum:
                return team_is_full

            # 判断该学生是否加入该竞赛的其他团队,待补充
            # 目前允许一个学生加入一个竞赛的多个团队
            update_tstudent_item["TSid"] = tsid
            update_tstudent_item["Sid"] = sid
            update_tstudent_item["TEid"] = teid
            update_tstudent_item["TStype"] = 1002
            update_tstudent_item["TSsubject"] = 1101

            response_of_update_tstudent = self.steams.update_tstudent_by_tsid(
                tsid, update_tstudent_item)
            if not response_of_update_tstudent and add_status:
                add_status = False
            sname = self.sstudent.get_sname_by_sid(sid)
            tename = self.steams.get_tename_by_teid(teid)
            message = JOIN_TEAM_SUCCESS.format(sname, tename)  # 信息报文
            uid2 = self.sinfor.get_uid2_by_pid(pid)
            response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                      message, 1200, 903, None,
                                                      teid, uid2)
            if not response_of_update_tstudent and add_status:
                add_status = False

            if not add_status:
                return system_error
            return join_team_success
        else:
            return param_miss

    # 教师同意加入,入口在我的信息中
    def sub_teacher(self):
        add_status = True
        update_tteacher_item = {}  # 新建空的json变量
        args = request.args.to_dict()  # 获取参数
        print args
        if not self.judgeData.inData("Uid", args) or not self.judgeData.inData(
                "sub_index", args):
            return param_miss

        uid = args["Uid"]
        sub_index = args["sub_index"]

        data = request.data  # 获取body体
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("Pid", data):
            return param_miss
        pid = data["Pid"]
        teid = self.sinfor.get_teid_by_pid(pid)
        tid = self.spersonal.get_tid_by_uid(uid)
        ttid = self.steams.get_ttid_by_teid_tid(teid, tid)

        if sub_index == 1102:
            update_tteacher_item["TTid"] = ttid
            update_tteacher_item["Tid"] = tid
            update_tteacher_item["TEid"] = teid
            update_tteacher_item["TTsubject"] = 1102

            response_of_update_tteacher = self.steams.update_tteacher_by_ttid(
                ttid, update_tteacher_item)
            if not response_of_update_tteacher and add_status:
                add_status = False

            tname = self.steacher.get_tname_by_tid(tid)
            tename = self.steams.get_tename_by_teid(teid)
            message = TEACHER_REFUSE_JOIN_TEAM.format(tname, tename)  # 信息报文
            uid2 = self.sinfor.get_uid2_by_pid(pid)
            response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                      message, 1200, 903, None,
                                                      teid, uid2)
            if not response_of_infor and add_status:
                add_status = False

            if not add_status:
                return system_error
            return refuse_join_team_success
        elif sub_index == 1101:
            # 根据团队id获取当前团队教师的数量,默认最大为1,超过则加入失败
            # 这里需要对teid进行防sql注入处理
            teacher_num = self.steams.get_tcount_by_teid(teid)
            if teacher_num >= 1:
                return team_is_full

            update_tteacher_item["TTid"] = ttid
            update_tteacher_item["Tid"] = tid
            update_tteacher_item["TEid"] = teid
            update_tteacher_item["TTsubject"] = 1101

            response_of_update_tteacher = self.steams.update_tteacher_by_ttid(
                ttid, update_tteacher_item)
            if not response_of_update_tteacher and add_status:
                add_status = False
            tname = self.steacher.get_tname_by_tid(tid)
            tename = self.steams.get_tename_by_teid(teid)
            message = TEACHER_JOIN_TEAM_SUCCESS.format(tname, tename)  # 信息报文
            uid2 = self.sinfor.get_uid2_by_pid(pid)
            response_of_infor = self.sinfor.add_infor(uuid.uuid4(), uid,
                                                      message, 1200, 903, None,
                                                      teid, uid2)
            if not response_of_infor and add_status:
                add_status = False

            if not add_status:
                return system_error
            return join_team_success
        else:
            return param_miss

    # 新增团队任务,入口在团队详情中
    def add_task(self):
        return system_error

    # 修改团队任务完成情况,入口在团队详情中
    def sub_task(self):
        return system_error

    # 修改团队任务内容,入口在团队详情中
    def update_task(self):
        return system_error

    # 删除团队,入口在我的团队中,实际修改团队的可用属性
    def delete_team(self):
        args = request.args.to_dict()  # 获取参数
        print args
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]

        data = request.data  # 获取body体
        # 判断body体非空
        if data == {} or str(data) == "":
            return param_miss
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("TEid", data):
            return param_miss

        teid = data["TEid"]
        sid = self.sstudent.get_sid_by_uid(uid)
        tstype = self.steams.get_tstype_by_teid_sid(teid, sid)

        if tstype != 1000:
            return none_permissions

        teuse = 702

        update_team_item = {}
        update_team_item["TEid"] = teid
        update_team_item["TEuse"] = teuse

        response_of_update_team = self.steams.update_teams_by_teid(
            teid, update_team_item)

        if not response_of_update_team:
            return system_error
        return delete_team_success

    # 删除团队学生,入口在团队详情中,实际修改团队学生表的属性
    def delete_student(self):
        args = request.args.to_dict()  # 获取参数
        print args
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]

        data = request.data  # 获取body体
        # 判断body体非空
        if data == {} or str(data) == "":
            return param_miss
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("TEid", data):
            return param_miss

        teid = data["TEid"]
        sid = self.sstudent.get_sid_by_uid(uid)
        tstype = self.steams.get_tstype_by_teid_sid(teid, sid)

        if tstype != 1000:
            return none_permissions

        tsid = self.steams.get_tsid_by_teid_sid(teid, sid)

        delete_student = {}
        delete_student["TSsubject"] = 1103

        response_of_delete_student = self.steams.update_tstudent_by_tsid(
            tsid, delete_student)

        if not response_of_delete_student:
            return system_error

        return delete_student_from_team_success

    # 删除团队教师,入口在团队详情中,实际修改团队教师表的属性
    def delete_teacher(self):
        args = request.args.to_dict()  # 获取参数
        print args
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]

        data = request.data  # 获取body体
        # 判断body体非空
        if data == {} or str(data) == "":
            return param_miss
        data = json.loads(data)

        # 判断body体中含有必要参数
        if not self.judgeData.inData("TEid", data):
            return param_miss

        teid = data["TEid"]
        tid = self.spersonal.get_tid_by_uid(uid)
        tstype = self.steams.get_tstype_by_teid_sid(teid, tid)

        if tstype != 1000:
            return none_permissions

        tsid = self.steams.get_tsid_by_teid_sid(teid, tid)

        delete_student = {}
        delete_student["TSsubject"] = 1103

        response_of_delete_student = self.steams.update_tstudent_by_tsid(
            tsid, delete_student)

        if not response_of_delete_student:
            return system_error

        return delete_student_from_team_success

    # 删除团队任务,入口在团队详情中
    def delete_task(self):
        return system_error
Пример #7
0
class CPersonal():
    def __init__(self):
        self.judgeData = JudgeData()  # 实例化
        self.spersonal = SPersonal()
        self.sstudent = SStudents()
        self.steacher = STeachers()
        self.suser = SUsers()
        self.scompetitions = SCompetitions()

    # 获取个人信息
    def myinfor(self):
        args = request.args.to_dict()  # 获取到的参数
        print(args)
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)
        # 判断系统是否异常
        if not self.spersonal.status:
            return system_error

        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            print(sid)
            if sid == None:
                return {}
            # 获取数据库中数据
            # 获取学生的基础信息
            student_abo = get_model_return_list(
                self.sstudent.get_student_abo_by_sid(sid))
            # 获取学生的技能信息
            student_tech = get_model_return_list(
                self.sstudent.get_student_tech_by_sid(sid))
            # 获取学生的竞赛信息
            student_use = get_model_return_list(
                self.sstudent.get_student_use_by_sid(sid))
            # 拼装返回结构体
            student_abo[0]["STech"] = student_tech
            student_abo[0]["SCUse"] = student_use
            search_student_abo_success["student_abo"] = student_abo
            return search_student_abo_success  # 已修改
        elif utype == 101:
            tid = self.spersonal.get_tid_by_uid(uid)

            # 获取教师的所有基础信息
            teacher_abo = get_model_return_list(
                self.steacher.get_teacher_abo_by_tid(tid))
            # 获取教师的所有竞赛信息
            teacher_use = get_model_return_list(
                self.steacher.get_teacher_use_by_tid(tid))
            # 将竞赛信息拼装进教师基础信息中
            teacher_abo[0]["TCuse"] = teacher_use
            search_teachers_abo_success["teacher_abo"] = teacher_abo
            return search_teachers_abo_success
        elif utype == 102:
            return none_permissions
        else:
            return none_identity

    # 新建个人信息
    def create_myinfor(self):
        args = request.args.to_dict()  # 获取到的参数
        print(args)
        form = request.data  # 获取到的body体
        print(form)
        # 转化为json
        form = json.loads(form)
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)
        # 判断系统正常
        if not self.spersonal.status:
            return system_error
        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            # 判断body中的必要参数是否缺失
            if not self.judgeData.inData("Sname", form) or not self.judgeData.inData("Sno", form) \
                    or not self.judgeData.inData("Suniversity", form) or not self.judgeData.inData("Sschool", form) \
                    or not self.judgeData.inData("Stel", form):
                return param_miss
            # 判断body中的非必要参数是否存在
            if not self.judgeData.inData("Sgrade", form):
                form["Sgrade"] = None
            if not self.judgeData.inData("Ssex", form):
                form["Ssex"] = None
            elif form["Ssex"] != 201 and form["Ssex"] != 202:
                return wrong_sex

            # 填写个人信息到数据库
            add_personal_abo = self.spersonal.add_student_abo_by_uid(
                str(uuid.uuid4()), args["Uid"], form["Sname"], form["Sno"],
                form["Suniversity"], form["Sschool"], form["Stel"],
                form["Sgrade"], form["Ssex"])
            # 判断插入是否成功
            if add_personal_abo:
                return add_personal_success
            else:
                return system_error
        elif utype == 101:
            # 判断body中的必要参数是否缺失
            if not self.judgeData.inData("Tname", form) or not self.judgeData.inData("Tno", form) \
                    or not self.judgeData.inData("Ttel", form) or not self.judgeData.inData("Tuniversity", form) \
                    or not self.judgeData.inData("Tschool", form):
                return param_miss
            # 判断body中的非必要参数是否存在
            if not self.judgeData.inData("Ttime", form):
                form["Ttime"] = None

            # 填写个人信息到数据库
            add_personal_abo = self.spersonal.add_teacher_abo_by_uid(
                str(uuid.uuid4()), args["Uid"], form["Tname"], form["Tno"],
                form["Ttel"], form["Tuniversity"], form["Tschool"],
                form["Ttime"])
            # 判断插入是否成功
            if add_personal_abo:
                return add_personal_success
            else:
                return system_error
        elif utype == 102:
            return none_permissions
        else:
            return none_identity

    # 新建个人技能
    def create_mytech(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        form = request.data  # 获取body
        print(form)

        # 转化为json
        form = json.loads(form)
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)
        # 判断系统正常
        if not self.spersonal.status:
            return system_error
        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            if sid == "":
                return none_personal
            # 缺失校检技能名称的过程
            for row in form:
                # 判断必填参数是否存在
                if not self.judgeData.inData("STname",
                                             row) or not self.judgeData.inData(
                                                 "STlevel", row):
                    return param_miss
                # 校检等级合法,1入门2一般3掌握4熟练5精通
                if row["STlevel"] > 5 or row["STlevel"] < 1:
                    return error_tech_level
                # 判断技能名称是否重复
                stname_list = self.sstudent.get_stname_by_sid(sid)
                if row["STname"] in stname_list:
                    return repeated_stname

                # 写入技能
                add_personal_tech = self.spersonal.add_student_tech_by_sid(
                    str(uuid.uuid4()), sid, row["STname"], row["STlevel"])

                # 判断系统异常
                if not add_personal_tech:
                    return system_error
            return add_student_tech_success
        elif utype == 101 or utype == 102:
            return none_permissions
        else:
            return none_identity

    # 新建个人比赛经历
    def create_myuse(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        form = request.data  # 获取body
        print(form)

        # 转化为json
        form = json.loads(form)
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)
        # 判断系统正常
        if not self.spersonal.status:
            return system_error
        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            if sid == "":
                return none_personal
            for row in form:
                # 判断必填参数缺失
                if not self.judgeData.inData("SCname",
                                             row) or not self.judgeData.inData(
                                                 "SCno", row):
                    return param_miss

                # 似乎应该校检一下两个参数,但是不知道应该怎么校检
                # 校检个人比赛经历中的竞赛名称重复
                scname_list = self.sstudent.get_scname_by_sid(sid)
                if row["SCname"] in scname_list:
                    return repeated_scname

                # 写入数据库
                add_personal_use = self.spersonal.add_student_use_by_sid(
                    str(uuid.uuid4()), sid, row["SCname"], row["SCno"])
                if not add_personal_use:
                    return system_error

            return add_personal_use_success
        elif utype == 101:
            tid = self.spersonal.get_tid_by_uid(uid)
            if tid == "":
                return none_personal
            for row in form:
                # 判断必填参数缺失
                if not self.judgeData.inData("TCname",
                                             row) or not self.judgeData.inData(
                                                 "TCno", row):
                    return param_miss
                # 判断非必填参数是否存在
                if not self.judgeData.inData("TCnum", row):
                    row["TCnum"] = 1

                # 似乎应该进行一些校检,但是不知道该怎么校检
                # 写入数据库
                add_personal_use = self.spersonal.add_teacher_use_by_tid(
                    str(uuid.uuid4()), tid, row["TCname"], row["TCno"],
                    row["TCnum"])
                if not add_personal_use:
                    return system_error
            return add_personal_use_success
        elif utype == 102:
            return none_permissions
        else:
            return none_identity

    # 更新个人信息
    def update_myinfor(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        # 判断参数中包含Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss
        form = request.data  # 获取body体
        print(form)
        form = json.loads(form)
        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)
        # 判断系统正常
        if not self.spersonal.status:
            return system_error

        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            # 判断body中的必要参数是否缺失
            if not self.judgeData.inData("Sname", form) or not self.judgeData.inData("Sno", form) \
                    or not self.judgeData.inData("Suniversity", form) or not self.judgeData.inData("Sschool", form) \
                    or not self.judgeData.inData("Stel", form):
                return param_miss
            if self.judgeData.inData(
                    "Ssex",
                    form) and form["Ssex"] != 201 and form["Ssex"] != 202:
                return wrong_sex
            # 修改数据库信息
            update_personal_abo = self.spersonal.update_student_abo_by_uid(
                uid, form)

            if not update_personal_abo:
                return system_error
            return update_personal_abo_success
        elif utype == 101:
            # 判断body中的必要参数是否缺失
            if not self.judgeData.inData("Tname", form) or not self.judgeData.inData("Tno", form) \
                    or not self.judgeData.inData("Ttel", form) or not self.judgeData.inData("Tuniversity", form) \
                    or not self.judgeData.inData("Tschool", form):
                return param_miss

            # 修改数据库信息
            update_personal_abo = self.spersonal.update_teacher_abo_by_uid(
                uid, form)

            if not update_personal_abo:
                return system_error
            return update_personal_abo_success
        elif utype == 102:
            return none_permissions
        else:
            return none_identity

    # 更新个人技能
    def update_mytech(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        form = request.data  # 获取body体
        print(form)
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss
        form = json.loads(form)
        # 判断body非空
        if form == {} or str(form) == "":
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)

        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            if sid == "":
                return none_personal
            # 缺失校检技能名称的过程
            for row in form:
                # 判断必填参数是否存在
                if not self.judgeData.inData("STname",
                                             row) or not self.judgeData.inData(
                                                 "STlevel", row):
                    return param_miss
                # 校检等级合法,1入门2一般3掌握4熟练5精通
                if row["STlevel"] > 5 or row["STlevel"] < 1:
                    return error_tech_level
                # 判断技能名称是否重复,这里判断有问题
                '''
                stname_list = self.spersonal.get_stname_by_sid(sid)
                if row["STname"] in stname_list:
                    return repeated_stname
                '''
                stid = row["STid"]
                # 更新数据库
                update_personal_tech = self.spersonal.update_student_tech_by_stid(
                    stid, row)

                if not update_personal_tech:
                    return system_error
            return update_personal_tech_success
        elif utype == 101 or utype == 102:
            return none_permissions
        else:
            return none_identity

    # 更新个人竞赛简历
    def update_myuse(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        form = request.data  # 获取body体
        print(form)
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss
        form = json.loads(form)
        # 判断body非空
        if form == {} or str(form) == "":
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)

        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            if sid == "":
                return none_personal
            for row in form:
                # 判断必填参数缺失
                if not self.judgeData.inData("SCname",
                                             row) or not self.judgeData.inData(
                                                 "SCno", row):
                    return param_miss

                # 似乎应该校检一下两个参数,但是不知道应该怎么校检
                scid = row["SCid"]

                # 更新数据库
                update_personal_use = self.spersonal.update_student_use_by_scid(
                    scid, row)

                if not update_personal_use:
                    return system_error

            return update_personal_use_success
        elif utype == 101:
            tid = self.spersonal.get_tid_by_uid(uid)
            if tid == "":
                return none_personal
            for row in form:
                # 判断必填参数缺失
                if not self.judgeData.inData("TCname",
                                             row) or not self.judgeData.inData(
                                                 "TCno", row):
                    return param_miss
                # 判断非必填参数是否存在
                if not self.judgeData.inData("TCnum", row):
                    row["TCnum"] = 1

                # 似乎应该进行一些校检,但是不知道该怎么校检
                # 获取tcid
                tcid = row["TCid"]
                # 更新数据库
                update_personal_use = self.spersonal.update_teacher_use_by_tcid(
                    tcid, row)
                if not update_personal_use:
                    return system_error
            return update_personal_use_success
        elif utype == 102:
            return none_permissions
        else:
            return none_identity

    # 删除个人技能
    def delete_mytech(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        form = request.data  # 获取body体
        print(form)
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss
        form = json.loads(form)
        # 判断body非空
        if form == {} or str(form) == "":
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)
        print(utype)

        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            # 缺失校检技能名称的过程
            for row in form:
                # 判断必填参数是否存在
                stid = row["STid"]
                # 更新数据库
                delete_personal_tech = self.spersonal.delete_student_tech_by_stid(
                    stid)

                if not delete_personal_tech:
                    return system_error
            return delete_personal_tech_success
        elif utype == 101 or utype == 102:
            return none_permissions
        else:
            return none_identity

    def delete_myuse(self):
        args = request.args.to_dict()  # 获取参数
        print(args)
        form = request.data  # 获取body体
        print(form)
        # 判断参数非空
        if not args:
            return param_miss
        # 判断参数中含有Uid
        if not self.judgeData.inData("Uid", args):
            return param_miss
        form = json.loads(form)
        # 判断body非空
        if form == {} or str(form) == "":
            return param_miss

        uid = args["Uid"]
        # 获取用户身份
        utype = self.suser.get_utype_by_uid(uid)

        # 判断用户身份,其中100为学生,101为教师,102为管理员
        if utype == 100:
            sid = self.sstudent.get_sid_by_uid(uid)
            for row in form:
                scid = row["SCid"]

                # 更新数据库
                delete_personal_use = self.spersonal.delete_student_use_by_scid(
                    scid)

                if not delete_personal_use:
                    return system_error

            return delete_personal_use_success
        elif utype == 101:
            tid = self.spersonal.get_tid_by_uid(uid)
            for row in form:
                # 判断必填参数缺失
                if not self.judgeData.inData("TCname", row):
                    return param_miss

                # 获取tcid
                tcid = row["TCid"]
                # 更新数据库
                delete_personal_use = self.spersonal.delete_teacher_use_by_tcid(
                    tcid)
                if not delete_personal_use:
                    return system_error
            return delete_personal_use_success
        elif utype == 102:
            return none_permissions
        else:
            return none_identity