def submit_train_place(): """ 功能1:数据库学生选课信息的更新 功能2: 实现计划树以及进度条的提交更新。 :return: """ """功能1:""" # 使用 request.get_json(force=True) 忽略mimetype twoData = request.get_json(force=True) train_plan = twoData['tree'] scores = twoData['scores'] #train_plan['name'] = "数据转换成功" print('反馈回来的数据是:') print(train_plan) data = train_plan['children'] array_finish = [0] * 120 #print(array_finish) for data_children in data: data_children = data_children['children'] #print(data_children) for data_children_child_1 in data_children: #print('data_children_child', data_children_child) data_children_child_1 = data_children_child_1['children'] for data_children_child in data_children_child_1: name = data_children_child['children'][0]['name'] color = data_children_child['children'][0]['itemStyle'][ 'borderColor'] #print(name, color) sql = "select CO_100 from education_plan WHERE CO_NAME='%s'" % name co_100 = query.query(sql) co_100 = co_100[0][0] if color == 'red': array_finish[int(co_100)] = 0 else: array_finish[int(co_100)] = 1 finish_co = '' for i in range(1, 119): if array_finish[i] == 1: finish_co += '1' else: finish_co += '0' print(finish_co) #print(array_finish) stu_id = session.get('stu_id') query.updateDatabase(stu_id, train_plan) query.updateScore(stu_id, scores) """功能2:""" train_plan_str = json.dumps(train_plan) train_plan_str = train_plan_str.replace("yellow", "green") train_plan = json.loads(train_plan_str) return jsonify(train_plan)
def submit_train_place(): """ 功能1:实现数据库学生选课信息的更新 功能2: 实现计划树以及进度条的提交更新。 :return: """ """功能1:""" # 入参 twoData = request.get_json(force=True) train_plan = {} if "tree" in twoData: train_plan = twoData['tree'] scores = {} if "scores" in twoData: scores = twoData['scores'] print(scores) # train_plan['name'] = "数据转换成功" print('反馈回来的数据是:') print(train_plan) # 从根节点找出孩子进行遍历 # data = train_plan['children'] # array_finish = [0] * 120 # # print(array_finish) # # 遍历第二层里面的每一个孩子 # for data_children in data: # data_children = data_children['children'] # # print(data_children) # # 对第三层遍历 # for data_children_child_1 in data_children: # # print('data_children_child', data_children_child) # data_children_child_1 = data_children_child_1['children'] # # 对第四层进行遍历 # for data_children_child in data_children_child_1: # # 获取name,color # name = data_children_child['children'][0]['name'] # color = data_children_child['children'][0]['itemStyle']['borderColor'] # # print(name, color) # # 用name查找co_100 # sql = "select CO_100 from EDUCATION_PLAN WHERE CO_NAME='%s'" % name # co_100 = query.query(sql) # co_100 = co_100[0][0] # # if color == 'red': # array_finish[int(co_100)] = 0 # else: # array_finish[int(co_100)] = 1 # finish_co = '' # for i in range(1, 119): # if array_finish[i] == 1: # finish_co += '1' # else: # finish_co += '0' # print(finish_co) # print(array_finish) stu_id = session.get('stu_id') # stu_id = 2016012107 # 更新选课计划 query.updateDatabase(stu_id, train_plan) # 更新选课记录 query.updateScore(stu_id, scores) return jsonify(query.get_plan_tree(stu_id))