def test():
        openid = 'oUasBj22KcIS113nNg788L85DGp4'
        db = MysqlUse()
        use = UseApply()
        num = db.selectStudentMessage('openid', openid)
        num = num[0]
        res = use.updateScheduleInformation(num[1], num[2], num[8])
        if 'error' in res:
            return {'code': 1, 'msg': res}
        return jsonify({'code': 0, 'data': res})
Exemple #2
0
def updateInfromation():
    db = MysqlUse()
    use = UseApply()
    num_all = db.sclectAllStudent()
    for even in num_all:
        res_score = use.updateScoreInformation(even[1], even[2])
        if 'error' in res_score:
            print({'code': 1, 'msg': res_score, 'id': even[0]})
        else:
            print({'code': 0, 'data': res_score, 'id': even[0]})
        res_schedule = use.updateScheduleInformation(even[1], even[2], even[8])
        if 'error' in res_schedule:
            print({'code': 1, 'msg': res_schedule, 'classroom': even[8]})
        else:
            print({'code': 0, 'data': res_schedule, 'classroom': even[8]})
def get_schedule():
    token = request.cookies.get('token')
    if not token:
        return jsonify({
            'code': 2,
        })
    else:
        sr = RedisUse()
        openid = sr.getTokenOpenid(token)
        if not openid:
            return jsonify({
                'code': 2,
            })
    #     openid = 'oUasBj22KcIS113nNg788L85DGp4'
        schedule_year = request.args.get('year')
        schedule_term = request.args.get('term')
        if schedule_term is None or schedule_year is None:
            return jsonify({'code': 1, 'msg': '参数错误'})
        use = UseApply()
        db = MysqlUse()
        res = db.selectStudentMessage('openid', openid)
        account = res[0][1]
        password = res[0][2]
        classroom = res[0][8]
        validate_schedule = db.selectSchedule(classroom, schedule_year, schedule_term)
        if not validate_schedule:
            sql_reschedule = use.getSchedule(account, password, classroom, schedule_year, schedule_term)
            if not sql_reschedule:
                data = {
                    'code': 1,
                    'msg': 'sql数据库错误,请联系管理员'
                }
                return jsonify(data)
            sql_res_schedule = db.selectSchedule(classroom, schedule_year, schedule_term)
            res_schedule = use.mangageSchedule(sql_res_schedule)
            data = {
                'code': 0,
                'data': res_schedule,
            }
            return jsonify(data)
        else:
            res_schedule = use.mangageSchedule(validate_schedule)
            data = {
                'code': 0,
                'data': res_schedule,
            }
            return jsonify(data)
 def getSchedule(self, account, password, classroom, schedule_year, schedule_term):
     db = MysqlUse()
     i = 0
     sch = SchoolApiGet()
     res_schedule = sch.get_schedule_info(account, password, schedule_year, schedule_term)
     while 'schedule' not in res_schedule:
         res_schedule = sch.get_schedule_info(account, password, schedule_year, schedule_term)
         i = i + 1
         if i >= 4:
             return res_schedule
     for day in range(len(res_schedule['schedule'])):
         for lesson in range(len(res_schedule['schedule'][day])):
             for x in range(len(res_schedule['schedule'][day][lesson])):
                 res_sql = db.insertSchedule(res_schedule['schedule_year'],  res_schedule['schedule_term'], day, lesson, classroom,  res_schedule['schedule'][day][lesson][x])
                 if not res_sql:
                     return False
     return True
def user_login():
    sr = RedisUse()
    db = MysqlUse()
    token = request.cookies.get('token')
    if not token:
        return jsonify({
            'code': 2,
        })
    else:
        openid = sr.getTokenOpenid(token)
        if not openid:
            return jsonify({
                'code': 2,
            })
        res_binding_openid = db.selectStudentMessage('openid', openid)
        if res_binding_openid:
            if res_binding_openid[0][1] and res_binding_openid[0][2]:
                data_isbinding = {
                    'isBind': 1,
                }
                data = {
                    'code': 0,
                    'data': data_isbinding,
                }
                return jsonify(data)
            else:
                data_isbinding = {
                    'isBind': 0,
                }
                data = {
                    'code': 0,
                    'data': data_isbinding,
                }
                return jsonify(data)
        else:
            data_isbinding = {
                'isBind': 0,
            }
            data = {
                'code': 0,
                'data': data_isbinding,
            }
            return jsonify(data)
def update_schedule():
    token = request.cookies.get('token')
    if not token:
        return jsonify({
            'code': 2,
        })
    else:
        sr = RedisUse()
        openid = sr.getTokenOpenid(token)
        if not openid:
            return jsonify({
                'code': 2,
            })
    db = MysqlUse()
    use = UseApply()
    num = db.selectStudentMessage('openid', openid)
    num = num[0]
    res = use.updateScheduleInformation(num[1], num[2], num[8])
    if 'error' in res:
        return {'code': 1, 'msg': res}
    return jsonify({'code': 0, 'data': res})
def user_untying():
    sr = RedisUse()
    db = MysqlUse()
    # token = request.cookies.get('token')
    # if not token:
    #     return jsonify({
    #         'code': 2,
    #     })
    # else:
    #     openid = sr.getTokenOpenid(token)
    openid = 'oUasBj22KcIS113nNg788L85DGp4'
    if not openid:
        return jsonify({
            'code': 2,
        })
    res_sel = db.selectStudentMessage('openid', openid)
    if not res_sel:
        return jsonify({'code': 1, 'msg': 'sql错误,请联系管理员'})
    res_untying = db.untyingStudent('openid', openid)
    if not res_untying:
        return jsonify({'code': 1, 'msg': 'sql错误,请联系管理员'})
    return jsonify({'code': 0})
 def updateScheduleInformation(self, account, password, classroom):
     db = MysqlUse()
     sch = SchoolApiGet()
     i = 0
     schedule_data = sch.get_schedule_info(account, password)
     while 'schedule' not in schedule_data:
         res_schedule = sch.get_schedule_info(account, password)
         i = i + 1
         if i >= 4:
             return res_schedule
     if not schedule_data['schedule']:
         return {'isScore': 1}
     sel_schedule = {
         'classroom': classroom,
         'school_year': schedule_data['schedule_year'],
         'term': schedule_data['schedule_term'],
     }
     validate_schedule = db.validateSchedule(sel_schedule)
     if validate_schedule:
         return {'isSchedule': 1}
     else:
         for day in range(len(schedule_data['schedule'])):
             for lesson in range(len(schedule_data['schedule'][day])):
                 for x in range(len(schedule_data['schedule'][day][lesson])):
                     res_sql = db.insertSchedule(schedule_data['schedule_year'], schedule_data['schedule_term'], day,
                                                 lesson, classroom, schedule_data['schedule'][day][lesson][x])
                     if not res_sql:
                         return False
         sel_schedule = {
             'classroom': classroom,
             'school_year': schedule_data['schedule_year'],
             'term': schedule_data['schedule_term'],
         }
         res_select = db.validateSchedule(sel_schedule)
         if not res_select:
             return {'isSchedule': 1}
         else:
             return {'isSchedule': 0}
 def getScore(self, account, password, score_year=None, score_term=None,):
     db = MysqlUse()
     sch = SchoolApiGet()
     i = 0
     school_data = sch.get_score_info(account, password, score_year, score_term)
     while 'score_info' not in school_data:
         school_data = sch.get_score_info(account, password, score_year, score_term)
         i = i + 1
         if i >= 4:
             return school_data
     res_allcollege_1 = db.updateStudentMessage('account', account, 'all_point', school_data['all_college']['pjzjd'])
     if not res_allcollege_1:
         return False
     res_allcollege_2 = db.updateStudentMessage('account', account, 'major_number', school_data['all_college']['zyzrs'])
     if not res_allcollege_2:
         return False
     for key_year, value in school_data['score_info'].items():
         for key_term, value_data in value.items():
             for res in value_data:
                 sql_res = db.insertScore(key_year, key_term, res, account)
                 # i = i + sql_res
                 if not sql_res:
                     return False
     return True
 def updateScoreInformation(self, account, password):
     db = MysqlUse()
     sch = SchoolApiGet()
     query_obj = {}
     data_school = []
     update_score_data = []
     insert_data = []
     l = 0
     school_data = sch.get_score_info(account, password)
     while 'score_info' not in school_data:
         school_data = sch.get_score_info(account, password)
         l += 1
         if l >= 4:
             return school_data
     for key_year, value in school_data['score_info'].items():
         for key_term, value_data in value.items():
             for res in value_data:
                 res['year'] = key_year
                 res['term'] = key_term
                 res['term_end_score'] = str(res['term_end_score'])
                 res['peace_score'] = str(res['peace_score'])
                 data_school.append(res)
     sel_data = {
         'account': account
     }
     res_sql_data = db.validateScore(sel_data)
     res_sql_data = self.mangageValidateScore(res_sql_data)
     if len(res_sql_data) < len(data_school):
         for id_data, k in enumerate(data_school):
             if k not in res_sql_data:
                 insert_data.append(k)
                 if 'bkcj' not in k.keys():
                     k['make_up_score'] = '0'
                 else:
                     k['make_up_score'] = k.pop('bkcj')
                 if 'cxcj' not in k.keys():
                     k['rebuild_score'] = '0'
                 else:
                     k['rebuild_score'] = k.pop('cxcj')
                 k['usual_score'] = k.pop('peace_score')
                 k['account'] = account
                 k['type'] = k.pop('lesson_nature')
                 k['code'] = k.pop('lesson_code')
                 res_insert = db.insertNewScore(k)
                 if not res_insert:
                     return {'error': res_insert}
         res_pjzjd = db.updateStudentMessage('account', account, 'all_point', school_data['all_college']['pjzjd'])
         if not res_pjzjd:
             return {'error': res_pjzjd}
         if insert_data:
             return {'isScore': 0, 'insert': insert_data, 'point': school_data['all_college']['pjzjd']}
         else:
             return {'isScore': 1}
     else:
         for i, j in zip(res_sql_data, data_school):
             different_all = list(diff(j, i))
             if different_all and 'add' not in different_all[0]:
                 for ever_row in different_all:
                     if ever_row[0] is 'change':
                             i[ever_row[1]] = j[ever_row[1]]
                             j['change'] = ever_row
                 i['usual_score'] = i.pop('peace_score')
                 i['type'] = i.pop('lesson_nature')
                 query_obj['code'] = i.pop('lesson_code')
                 query_obj['term'] = i.pop('term')
                 query_obj['year'] = i.pop('year')
                 res_sql = db.updateDateScore(query_obj, i)
                 if not res_sql:
                     return {'error': res_sql}
                 i['code'] = query_obj['code']
                 i['term'] = query_obj['term']
                 i['year'] = query_obj['year']
                 i['change'] = j['change']
                 update_score_data.append(i)
     res_pjzjd = db.updateStudentMessage('account', account, 'all_point', school_data['all_college']['pjzjd'])
     if not res_pjzjd:
         return {'error': res_pjzjd}
     if update_score_data:
         return {'isScore': 0, 'update': update_score_data, 'point': school_data['all_college']['pjzjd']}
     else:
         return {'isScore': 1}
def get_score():
    token = request.cookies.get('token')
    if not token:
        return jsonify({
            'code': 2,
        })
    else:
        sr = RedisUse()
        openid = sr.getTokenOpenid(token)
        if not openid:
            return jsonify({
                'code': 2,
            })
        db = MysqlUse()
        sch = SchoolApiGet()
        use = UseApply()
        res = db.selectStudentMessage('openid', openid)
        if not res:
            return jsonify({'code': 1, 'msg': '查找sql错误,请联系管理员'})
        account = res[0][1]
        password = res[0][2]
        point = res[0][9]
        score_year = request.args.get('year')
        score_term = request.args.get('term')
        data_query_score = {
            'year': score_year,
            'term': score_term,
        }
        validate_score = db.selectScore(account, {'term': None, 'year': None})
        if not validate_score:
            sql_res = use.getScore(account, password)
            if sql_res:
                sql_res_score = db.selectScore(account, data_query_score)
                if sql_res_score:
                    sql_res_point = db.selectStudentMessage('account', account)
                    res_score = use.manageScore(sql_res_score)
                    data = {
                        'code': 0,
                        'data': res_score,
                        'point': sql_res_point[0][9],
                    }
                    return jsonify(data)
                else:
                    data = {
                        'code': 1,
                        'msg': '查找成绩sql错误,请联系管理员',
                        'other': sql_res,
                    }
                    return jsonify(data)
            else:
                data = {
                    'code': 1,
                    'msg': sql_res
                }
                return jsonify(data)
        else:
            if point:
                sql_res_score = db.selectScore(account, data_query_score)
                sql_res_point = db.selectStudentMessage('account', account)
                res_score = use.manageScore(sql_res_score)
                data = {
                    'code': 0,
                    'data': res_score,
                    'point': sql_res_point[0][9],
                }
                return jsonify(data)
            else:
                school_data = sch.get_score_info(account, password)
                res_all_college_point = db.updateStudentMessage('account', account, 'all_point', school_data['all_college']['pjzjd'])
                if not res_all_college_point:
                    return jsonify({'code': 1, 'msg': 'sql数据库错误'})
                res_all_college_major_num = db.updateStudentMessage('account', account, 'major_number', school_data['all_college']['zyzrs'])
                if not res_all_college_major_num:
                    return jsonify({'code': 1, 'msg': 'sql数据库错误'})
                sql_res_score = db.selectScore(account, data_query_score)
                sql_res_point = db.selectStudentMessage('account', account)
                res_score = use.manageScore(sql_res_score)
                data = {
                    'code': 0,
                    'data': res_score,
                    'point': sql_res_point[0][9],
                }
                return jsonify(data)
def user_binding():
    token = request.cookies.get('token')
    if not token:
        return jsonify({
            'code': 2,
        })
    else:
        sr = RedisUse()
        openid = sr.getTokenOpenid(token)
        if not openid:
            return jsonify({
                'code': 2,
            })
        db = MysqlUse()
        sch = SchoolApiGet()
        times = str(time.time()).split('.', 1)
        times = times[0]
        account = request.form.get('account')
        password = request.form.get('password')
        res = sch.validate_user(account, password)
        if res:
            return jsonify(res)
        res_sel = db.selectStudentMessage('openid', openid)
        if res_sel:
            res_account = db.updateStudentMessage('openid', openid, 'account', account)
            if not res_account:
                return jsonify({'code': 1, 'msg': 'sql错误,请联系管理员'})
            res_password = db.updateStudentMessage('openid', openid, 'password', password)
            if not res_password:
                return jsonify({'code': 1, 'msg': 'sql错误,请联系管理员'})
            return jsonify({'code': 0})
        else:
            redis_result_nature = sr.getOpenidNatureAll(openid)
            if not redis_result_nature:
                data_redis_none = {
                    'code': 1,
                    'msg': 'redis数据库错误,请联系管理员'
                }
                return jsonify(data_redis_none)
            else:
                data_redis = {
                    'account': account,
                    'password': password,
                    'binding_time': times,
                    'major': 'NULL',
                    'email': 'NULL',
                    'college': 'NULL',
                    'full_name': 'NULL',
                    'img': redis_result_nature['img'],
                    'nickname': redis_result_nature['nickname'],
                    'openid': openid,
                    'classroom': 'NULL',
                    'all_point': 'NULL',
                    'major_number': 'NULL',
                }
                sql_result = db.insertStudentMessage(data_redis)
                if not sql_result:
                    data_res = {
                        'code': 1,
                        'msg': 'sql数据库添加错误,请联系管理员'
                    }
                    return jsonify(data_res)
                else:
                    data = {
                        'code': 0
                    }
                    return jsonify(data)
def get_student_info():
    token = request.cookies.get('token')
    if not token:
        return jsonify({
            'code': 2,
        })
    else:
        sr = RedisUse()
        openid = sr.getTokenOpenid(token)
        if not openid:
            return jsonify({
                'code': 2,
            })
        db = MysqlUse()
        sch = SchoolApiGet()
        res = db.selectStudentMessage('openid', openid)
        if not res:
            return jsonify({'code': 1, 'msg': 'sql错误,请联系管理员'})
        if res[0][4] and res[0][6] and res[0][7] and res[0][8]:
            data_res = {
                "student_name": res[0][4],
                "student_xy": res[0][6],
                "student_xzb": res[0][8],
                "student_zy": res[0][7],
                "img": res[0][11],
            }
            data = {
                'code': 0,
                'data': data_res,
            }
            return jsonify(data)
        else:
            account = res[0][1]
            password = res[0][2]
            student_info = sch.get_student(account, password)
            if 'error' in student_info:
                return jsonify({
                    'code': 1,
                    'msg': student_info
                })
            res_sql = db.insertStudentOther(openid, student_info)
            if res_sql:
                res = db.selectStudentMessage('openid', openid)
                data_res = {
                    "student_name": res[0][4],
                    "student_xy": res[0][6],
                    "student_xzb": res[0][8],
                    "student_zy": res[0][7],
                    "img": res[0][11],
                }
                data = {
                    'code': 0,
                    'data': data_res,
                }
                return jsonify(data)
            else:
                data = {
                    'code': 1,
                    'msg': 'sql运行错误,请联系管理员'
                }
                return jsonify(data)