Ejemplo n.º 1
0
class CReviews():
    def __init__(self):
        from service.SReviews import SReviews
        self.sreviews = SReviews()
        from service.SUsers import SUsers
        self.susers = SUsers()

    def reviews_list(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Cid" not in args:
            return param_miss

        Cid = args["Cid"]
        all_review = self.sreviews.get_review_by_cid(Cid)
        data = []
        for row in all_review:
            data_item = {}
            data_item["Uid"] = row.Uid
            data_item["Uname"] = self.susers.get_uname_by_uid(row.Uid)
            data_item["RUid"] = row.RUid
            data_item["RUname"] = self.susers.get_uname_by_uid(row.RUid)
            data_item["Rabo"] = row.Rabo
            data_item["Rtime"] = row.Rtime
            data.append(data_item)

        from config.requests import response_ok
        response_ok["data"] = data
        return response_ok

    def add_review(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Uid" not in args or "Cid" not in args:
            return param_miss

        Uid = args["Uid"]
        Cid = args["Cid"]
        RUid = args["RUid"]

        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)

        if "Rabo" not in data:
            return param_miss
        Rabo = data["Rabo"]
        add_review = self.sreviews.new_review(Uid, Cid, RUid, Rabo)
        if not add_review:
            return system_error
        from config.requests import response_ok
        return response_ok
Ejemplo n.º 2
0
 def __init__(self):
     self.judgeData = JudgeData()  # 实例化
     self.spersonal = SPersonal()
     self.sstudent = SStudents()
     self.steacher = STeachers()
     self.suser = SUsers()
     self.scompetitions = SCompetitions()
Ejemplo n.º 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()
Ejemplo n.º 4
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
Ejemplo n.º 5
0
class CUsers():
    def __init__(self):
        from service.SUsers import SUsers
        self.susers = SUsers()

    def login(self):
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Uname" not in data or "Upwd" not in data:
            return param_miss

        Uname = data["Uname"]
        list_uname = self.susers.get_all_user_name()

        if list_uname == False:
            return system_error

        if Uname not in list_uname:
            from config.requests import no_tel
            return no_tel

        upwd = self.susers.get_upwd_by_uname(Uname)
        if upwd != data["Upwd"]:
            from config.requests import wrong_pwd
            return wrong_pwd

        Uid = self.susers.get_uid_by_uname(Uname)

        from config.requests import login_ok
        login_ok["data"] = {}
        login_ok["data"]["Uid"] = Uid

        return login_ok
Ejemplo n.º 6
0
class CWaters():
    def __init__(self):
        from service.SWaters import SWaters
        self.swaters = SWaters()

        from service.SUsers import SUsers
        self.susers = SUsers()

    def my_water(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Uid" not in args:
            return param_miss

        Uid = args["Uid"]

        my_water_list = self.swaters.get_water_list_by_uid(Uid)
        if not my_water_list:
            return system_error
        data = []
        for row in my_water_list:
            data_item = {}
            data_item["Wid"] = row.Wid
            data_item["Wyear"] = row.Wyear
            data_item["Wmonth"] = row.Wmonth
            data_item["Wpay"] = row.Wpay
            data_item["Wstatus"] = row.Wstatus
            data.append(data_item)

        from config.requests import response_ok
        response_ok["data"] = data
        return response_ok

    def update_wstatus(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="
        data = request.data
        print "======================args==========================="
        print data
        print "======================args==========================="
        data = json.loads(data)

        if "Uid" not in args or "Wid" not in args:
            return param_miss

        Uid = args["Uid"]
        Wid = args["Wid"]
        if "Wpay" not in data or "Wstatus" not in data:
            return param_miss

        Wstatus = data["Wstatus"]
        Wpay = data["Wpay"]
        if Wstatus != 601:
            return
        update_water = {}
        update_water["Wstatus"] = 602

        Ucoin = self.susers.get_ucoin_by_uid(Uid)
        Ucoin_update = Ucoin - Wpay
        update_users = {}
        update_users["Ucoin"] = Ucoin_update

        update_ucoin = self.susers.update_ucoin_by_uid(Uid, update_users)
        if not update_ucoin:
            return system_error

        update_water_status = self.swaters.update_water_by_wid(
            Wid, update_water)
        if not update_water_status:
            return system_error
        from config.requests import response_ok
        return response_ok
Ejemplo n.º 7
0
    def __init__(self):
        from service.SWaters import SWaters
        self.swaters = SWaters()

        from service.SUsers import SUsers
        self.susers = SUsers()
Ejemplo n.º 8
0
 def __init__(self):
     self.judgeData = JudgeData()  #全局实例化
     self.susers = SUsers()
Ejemplo n.º 9
0
class CUsers():
    def __init__(self):
        self.judgeData = JudgeData()  #全局实例化
        self.susers = SUsers()

    #实现登录的数据处理
    def login(self):
        form = request.data  #获取前端发送的body体
        print str(form)
        #判断body体不为空
        if str(form) == "" or str(form) == "[]":
            return param_miss
        form = json.loads(form)
        #判断必要存在的参数
        if not self.judgeData.inData(
                "Uname", form) or not self.judgeData.inData("Upwd", form):
            return param_miss

        list_uname = self.susers.get_all_user_name()  #获取数据库中存在的uname
        #判断uname存在
        if form["Uname"] not in list_uname:
            return
        Upwd = self.susers.get_upwd_by_uname(form["Uname"])  #根据用户名获取数据库的密码
        #判断session是否异常
        if Upwd == False:
            return system_error
        #判断用户名与密码匹配
        if Upwd != form["Upwd"]:
            return error_upwd

        Uid = self.susers.get_uid_by_uname(form["Uname"])  #根据用户名获取数据库的id
        Utype = self.susers.get_utype_by_uid(Uid)

        login_ok["messages"]["Uid"] = Uid  #将获取到的内容放置到body中
        login_ok["messages"]["Utype"] = Utype

        return login_ok

    #实现注册的数据处理
    def register(self):

        form = request.data  #获取前端发送的body体
        print request.values
        #print str(form)
        #判断body体不为空
        if str(form) == "" or str(form) == "[]":
            return param_miss
        print form
        form = json.loads(form)

        #判断必要参数存在
        if not self.judgeData.inData("Uname",form) or not self.judgeData.inData("Upwd",form) \
            or not self.judgeData.inData("Utype", form):
            return param_miss

        list_uname = self.susers.get_all_user_name()  #获取数据库中存在的uname
        #判断session是否异常
        if list_uname == False:
            return system_error
        #判断uname唯一
        if form["Uname"] in list_uname:
            return repeated_name

        is_register = self.susers.add_user(uuid.uuid4(), form["Uname"],
                                           form["Upwd"], form["Utype"])  #写入数据库
        #判断写入数据库的响应
        if is_register:
            return register_ok
        else:
            return system_error
Ejemplo n.º 10
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
Ejemplo n.º 11
0
class CCards():
    def __init__(self):
        from service.SCards import SCards
        self.scards = SCards()
        from service.SUsers import SUsers
        self.susers = SUsers()

    def card_list(self):
        all_card = self.scards.get_all_card()
        data = []
        for row in all_card:
            data_item = {}
            data_item["Cid"] = row.Cid
            data_item["Uname"] = self.susers.get_uname_by_uid(row.Uid)
            data_item["Cname"] = row.Cname
            data_item["Cabo"] = row.Cabo
            data_item["Cstatus"] = row.Cstatus
            data_item["Ctime"] = row.Ctime
            data.append(data_item)

        from config.requests import response_ok
        response_ok["data"] = data
        return response_ok

    def card_abo(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Cid" not in args:
            return param_miss

        Cid = args["Cid"]

        card_abo_all = self.scards.get_card_abo_by_cid(Cid)
        data = {}
        data["Uname"] = self.susers.get_uname_by_uid(card_abo_all.Uid)
        data["Uid"] = card_abo_all.Uid
        data["Cname"] = card_abo_all.Cname
        data["Cabo"] = card_abo_all.Cabo
        data["Cstatus"] = card_abo_all.Cstatus
        data["Ctime"] = card_abo_all.Ctime

        from config.requests import response_ok
        response_ok["data"] = data
        return response_ok

    def new_card(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Uid" not in args:
            return param_miss

        Uid = args["Uid"]

        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Cname" not in data or "Cabo" not in data:
            return param_miss

        Cname = data["Cname"]
        Cabo = data["Cabo"]
        add_card = self.scards.add_new_card(Uid, Cname, Cabo)

        if not add_card:
            return system_error
        from config.requests import response_ok
        return response_ok
Ejemplo n.º 12
0
 def __init__(self):
     from service.SReviews import SReviews
     self.sreviews = SReviews()
     from service.SUsers import SUsers
     self.susers = SUsers()
Ejemplo n.º 13
0
 def __init__(self):
     from service.STasks import STasks
     self.stask = STasks()
     from service.SUsers import SUsers
     self.susers = SUsers()
Ejemplo n.º 14
0
class CTasks():
    def __init__(self):
        from service.STasks import STasks
        self.stask = STasks()
        from service.SUsers import SUsers
        self.susers = SUsers()

    def task_list(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        # 搜索

        tasks_list = self.stask.get_task_list()
        if not tasks_list:
            return system_error
        data = []
        for row in tasks_list:
            data_item = {}
            data_item["Tid"] = row.Tid
            data_item["Tname"] = row.Tname
            data_item["Tcointype"] = row.Tcointype
            data_item["Tcoinnum"] = row.Tcoinnum
            data_item["Tstatus"] = row.Tstatus
            data_item["Ttype"] = row.Ttype
            data.append(data_item)
        from config.requests import response_ok
        response_ok["data"] = data
        return response_ok

    def task_abo(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Tid" not in args:
            return param_miss

        data = {}
        task_abo = self.stask.get_task_abo_by_tid(args["Tid"])
        if not task_abo:
            return system_error
        data["Tid"] = task_abo.Tid
        data["Tname"] = task_abo.Tname
        data["Tcointype"] = task_abo.Tcointype
        data["Tcoinnum"] = task_abo.Tcoinnum
        data["Tstatus"] = task_abo.Tstatus
        data["Ttype"] = task_abo.Ttype
        data["Tabo"] = task_abo.Tabo
        data["Tlocation"] = task_abo.Tlocation
        data["Uname"] = self.susers.get_utruename_by_uid(task_abo.Uid)
        from config.requests import response_ok
        response_ok["data"] = data
        return response_ok

    def new_task(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Uid" not in args:
            return param_miss

        Uid = args["Uid"]

        Ustatus = self.susers.get_ustatus_by_uid(Uid)
        if not Ustatus:
            return system_error

        if int(Ustatus) != 103:
            from config.requests import subject_not_pass
            return subject_not_pass

        tasks = {}
        if "Tname" in data:
            tasks["Tname"] = data["Tname"]
        if "Tcoinnum" in data:
            tasks["Tcoinnum"] = data["Tcoinnum"]
        if "Tlocation" in data:
            tasks["Tlocation"] = data["Tlocation"]
        if "Tabo" in data:
            tasks["Tabo"] = data["Tabo"]
        if "Ttype" in data:
            tasks["Ttype"] = data["Ttype"]
        if tasks == {}:
            return param_miss
        tasks["Uid"] = Uid
        tasks["Tstatus"] = 601
        if "Tcointype" in data:
            tasks["Tcointype"] = data["Tcointype"]
        else:
            tasks["Tcointype"] = 401

        add_task = self.stask.add_a_task(tasks["Tname"], tasks["Tcointype"], tasks["Tcoinnum"], tasks["Tlocation"],
                                         tasks["Tabo"], tasks["Tstatus"], tasks["Ttype"], tasks["Uid"])

        if not add_task:
            return system_error
        from config.requests import create_task_success
        return create_task_success

    def update_task_status(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Uid" not in args or "Tid" not in args:
            return param_miss

        Uid = args["Uid"]
        Tid = args["Tid"]

        uid = self.stask.get_uid_by_tid(Tid)
        if uid != Uid:
            from config.requests import no_permission
            return no_permission

        if "Tstatus" not in data:
            return param_miss

        Tstatus = data["Tstatus"]

        status = [603, 604]
        if Tstatus not in status:
            return param_miss
        task_status = {}
        task_status["Tstatus"] = Tstatus

        update_task = self.stask.update_taskstatus_by_tid(Tid, task_status)

        if not update_task:
            return system_error

        from config.requests import update_task_success
        return update_task_success

    def get_task(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Uid" not in args or "Tid" not in args:
            return param_miss

        Uid = args["Uid"]
        Tid = args["Tid"]

        uid = self.stask.get_uid_by_tid(Tid)
        if uid == Uid:
            from config.requests import no_permission
            return no_permission

        ttype = self.stask.get_ttype_by_tid(Tid)
        if ttype == 502:
            task_status = {}
            task_status["Tstatus"] = 602
            update_task = self.stask.update_taskstatus_by_tid(Tid, task_status)
            if not update_task:
                return system_error
        add_task_user = self.stask.new_task_user(Tid, Uid)
        if not add_task_user:
            return system_error

        from config.requests import get_task_success
        return get_task_success
Ejemplo n.º 15
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
Ejemplo n.º 16
0
class MakeData():
    def __init__(self):
        self.student = SStudents()
        self.teacher = STeachers()
        self.personal = SPersonal()
        self.competition = SCompetitions()
        self.user = SUsers()
        self.team = STeams()
        self.infor = SInfor()

    def make_id(self):
        user_ids = []
        student_ids = []
        teacher_ids = []
        competition_ids = []
        team_ids = []
        i = 0
        while i < 22:
            user_ids.append(uuid.uuid4())
            student_ids.append(uuid.uuid4())
            teacher_ids.append(uuid.uuid4())
            competition_ids.append(uuid.uuid4())
            team_ids.append(uuid.uuid4())
            i = i + 1
        return user_ids, student_ids, teacher_ids, competition_ids, team_ids

    def add_users(self, user_ids):
        i = 0
        name = "test"
        pwd = "123"
        utype = 100
        while i < 22:
            self.user.add_user(user_ids[i], name + str(i), pwd, utype)
            i = i + 1
            if i > 10:
                utype = 101

    def add_students(self, user_ids, student_ids):
        i = 0
        name = "student"
        no = "130323"
        university = "杭州电子科技大学"
        school = "管理学院"
        tel = "135880460"
        grade = 2018
        sex = 201
        while i < 11:
            self.personal.add_student_abo_by_uid(student_ids[i], user_ids[i],
                                                 name + str(i), no + str(i),
                                                 university, school,
                                                 tel + str(i), grade, sex)
            i = i + 1
            if i > 5:
                sex = 202

    def add_teachers(self, user_ids, teacher_ids):
        i = 0
        name = "teacher"
        no = "7403"
        university = "杭州电子科技大学"
        school = "管理学院"
        tel = "177064411"
        while i < 11:
            self.personal.add_teacher_abo_by_uid(user_ids[i + 11],
                                                 teacher_ids[i], name + str(i),
                                                 no, tel + str(i) + str(i),
                                                 university, school, i + 1)
            i = i + 1

    def add_competitions(self, competition_ids):
        i = 0
        name = "test_competition"
        level = 1
        start = "2018-01-22"
        end = "2019-01-22"
        min = 3
        max = 5
        own = "浙江团省委"
        abo = "测试数据"
        while i < 22:
            self.competition.add_competitions(competition_ids[i],
                                              name + str(i), i, level, start,
                                              end, min, max, own, abo)
            i = i + 1

    def add_team(self, team_ids, competition_ids):
        i = 0
        name = "test_team"
        while i < 22:
            self.team.add_team(team_ids[i], name + str(i), competition_ids[i],
                               701, 5)
            i = i + 1

    def add_tsstudent(self, team_ids, student_ids):
        i = 0
        while i < 6:
            self.team.add_student_in_team(uuid.uuid4(), team_ids[i],
                                          student_ids[i], 1000, 1101)
            self.team.add_student_in_team(uuid.uuid4(), team_ids[i],
                                          student_ids[i + 1], 1001, 1101)
            self.team.add_student_in_team(uuid.uuid4(), team_ids[i],
                                          student_ids[i + 2], 1001, 1101)
            self.team.add_student_in_team(uuid.uuid4(), team_ids[i],
                                          student_ids[i + 3], 1002, 1101)
            self.team.add_student_in_team(uuid.uuid4(), team_ids[i],
                                          student_ids[i + 4], 1002, 1101)
            self.team.add_student_in_team(uuid.uuid4(), team_ids[i],
                                          student_ids[i + 5], 1002, 1102)
            i = i + 1

    def add_tsteacher(self, team_ids, teacher_ids):
        i = 0
        while i < 6:
            self.team.add_teacher_in_team(uuid.uuid4(), team_ids[i],
                                          teacher_ids[i], 1)
            i = i + 1

    def add_stech(self, student_ids):
        i = 0
        name = "test_tech"
        while i < 11:
            self.personal.add_student_tech_by_sid(uuid.uuid4(), student_ids[i],
                                                  name + str(i), i % 5 + 1)
            self.personal.add_student_tech_by_sid(uuid.uuid4(), student_ids[i],
                                                  name + str(i + 1), i % 5 + 1)
            i = i + 1

    def add_scuse(self, student_ids):
        i = 0
        name = "测试竞赛简历"
        no = "一等奖"
        while i < 11:
            self.personal.add_student_use_by_sid(uuid.uuid4(), student_ids[i],
                                                 name + "1", no)
            self.personal.add_student_use_by_sid(uuid.uuid4(), student_ids[i],
                                                 name + "2", no)
            i = i + 1

    def add_tcuse(self, teacher_ids):
        i = 0
        name = "测试竞赛简历"
        no = "一等奖"
        while i < 11:
            self.personal.add_teacher_use_by_tid(uuid.uuid4(), teacher_ids[i],
                                                 name + "1", no, i)
            i = i + 1
Ejemplo n.º 17
0
class CUsers():
    def __init__(self):
        from service.SUsers import SUsers
        self.susers = SUsers()

    def user_info(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="

        if "Uid" not in args:
            return param_miss

        Uid = args["Uid"]

        user_info = self.susers.get_userinfo_by_uid(Uid)

        Utel = user_info.Utel
        Uname = user_info.Uname
        Ucardno = user_info.Ucardno
        Usex = user_info.Usex
        Ucoin = user_info.Ucoin
        Ulive = user_info.Ulive

        from config.requests import response_ok
        response_ok["data"] = {}
        response_ok["data"]["Utel"] = Utel
        response_ok["data"]["Uname"] = Uname
        response_ok["data"]["Ucardno"] = Ucardno
        response_ok["data"]["Usex"] = Usex
        response_ok["data"]["Ucoin"] = Ucoin
        response_ok["data"]["Ulive"] = Ulive

        return response_ok

    def register(self):
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Utel" not in data or "Upwd" not in data:
            return param_miss

        list_utel = self.susers.get_all_user_tel()

        if list_utel == False:
            return system_error

        if data["Utel"] in list_utel:
            from config.requests import repeat_tel
            return repeat_tel

        is_register = self.susers.regist_user(data["Utel"], data["Upwd"])
        if is_register:
            from config.requests import register_ok
            return register_ok
        else:
            return system_error

    def login(self):
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Utel" not in data or "Upwd" not in data:
            return param_miss

        Utel = data["Utel"]
        list_utel = self.susers.get_all_user_tel()

        if list_utel == False:
            return system_error

        if Utel not in list_utel:
            from config.requests import no_tel
            return no_tel

        upwd = self.susers.get_upwd_by_utel(Utel)
        if upwd != data["Upwd"]:
            from config.requests import wrong_pwd
            return wrong_pwd

        Uid = self.susers.get_uid_by_utel(Utel)

        from config.requests import login_ok
        login_ok["data"] = {}
        login_ok["data"]["Uid"] = Uid

        return login_ok

    def update_info(self):
        args = request.args.to_dict()
        print "======================args==========================="
        print args
        print "======================args==========================="
        data = request.data
        print "======================data==========================="
        print data
        print "======================data==========================="
        data = json.loads(data)
        if "Uid" not in args:
            return param_miss

        users = {}
        Uid = args["Uid"]
        if "Uname" in data:
            Uname = data["Uname"]
            users["Uname"] = Uname
        if "Usex" in data:
            Usex = data["Usex"]
            users["Usex"] = Usex
        if "Ulive" in data:
            Ulive = data["Ulive"]
            users["Ulive"] = Ulive
        if "Ucardno" in data:
            Ucardno = data["Ucardno"]
            users["Ucardno"] = Ucardno
        if "Ucoin" in data:
            Ucoin = data["Ucoin"]
            users["Ucoin"] = Ucoin

        if users == {}:
            return param_miss

        update_info = self.susers.update_userinfo_by_uid(users, Uid)

        if not update_info:
            return system_error

        from config.requests import success_update_uinfo
        return success_update_uinfo
Ejemplo n.º 18
0
 def __init__(self):
     from service.SCards import SCards
     self.scards = SCards()
     from service.SUsers import SUsers
     self.susers = SUsers()