123
This commit is contained in:
parent
99b6db2138
commit
defc9a5714
|
@ -11,10 +11,9 @@ function TrainPods(){
|
||||||
const FindPodsFunc=await axios.post('/api/teacher/list_pods')
|
const FindPodsFunc=await axios.post('/api/teacher/list_pods')
|
||||||
setPods(FindPodsFunc.data)
|
setPods(FindPodsFunc.data)
|
||||||
}catch{
|
}catch{
|
||||||
|
alert('出错')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
FindPodsFunc()
|
FindPodsFunc()
|
||||||
},[])
|
},[])
|
||||||
|
@ -25,8 +24,7 @@ function TrainPods(){
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
alert('删除成功')
|
alert('删除成功')
|
||||||
// eslint-disable-next-line no-restricted-globals
|
window.location.reload();
|
||||||
location.reload();
|
|
||||||
}catch{
|
}catch{
|
||||||
alert('出错')
|
alert('出错')
|
||||||
}
|
}
|
||||||
|
@ -42,11 +40,9 @@ function TrainPods(){
|
||||||
setSrcData(FindSrcc.data['data'])
|
setSrcData(FindSrcc.data['data'])
|
||||||
setisTrue(false)
|
setisTrue(false)
|
||||||
}catch{
|
}catch{
|
||||||
alert('SrcDAta出错')
|
alert('SrcData出错')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// // eslint-disable-next-line no-restricted-globals
|
|
||||||
//
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className='body-right-Pods'>
|
<div className='body-right-Pods'>
|
||||||
|
@ -93,9 +89,6 @@ function TrainPods(){
|
||||||
</div>
|
</div>
|
||||||
<button onClick={()=>setisTrue(!isTrue)} style={{marginLeft:'600px'}} className='srcbtn'>返回</button>
|
<button onClick={()=>setisTrue(!isTrue)} style={{marginLeft:'600px'}} className='srcbtn'>返回</button>
|
||||||
</table>}
|
</table>}
|
||||||
<button onClick={()=>{
|
|
||||||
console.log(Pods);
|
|
||||||
}}></button>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import React, { useEffect, useState } from 'react';
|
||||||
function TrainManage(){
|
function TrainManage(){
|
||||||
const teacher_ID=localStorage.getItem('islogin')
|
const teacher_ID=localStorage.getItem('islogin')
|
||||||
const [Data,setData]=useState()
|
const [Data,setData]=useState()
|
||||||
|
const [testID,settestID]=useState()
|
||||||
|
const [TrainData,setTrainData]=useState()
|
||||||
//获取发布的实训
|
//获取发布的实训
|
||||||
const getTrainfunc=async()=>{
|
const getTrainfunc=async()=>{
|
||||||
try{
|
try{
|
||||||
|
@ -23,6 +25,22 @@ function TrainManage(){
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
getTrainfunc()
|
getTrainfunc()
|
||||||
},[])
|
},[])
|
||||||
|
|
||||||
|
const getTrainData=async ()=>{
|
||||||
|
try{
|
||||||
|
const getTrainDataSrc=await axios.post('/api/teacher/getTrainData',{
|
||||||
|
testID
|
||||||
|
})
|
||||||
|
setTrainData(getTrainDataSrc.data['data'])
|
||||||
|
}catch{
|
||||||
|
alert('getTrainData出错')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
getTrainData()
|
||||||
|
},[testID])
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className='body-trainmanage'>
|
<div className='body-trainmanage'>
|
||||||
<p className='title'>已结束的实训</p>
|
<p className='title'>已结束的实训</p>
|
||||||
|
@ -33,7 +51,7 @@ function TrainManage(){
|
||||||
<li key={key}>
|
<li key={key}>
|
||||||
<span>实训ID:{Data[key][10]}</span>
|
<span>实训ID:{Data[key][10]}</span>
|
||||||
<h6 className='TrainTitle'>实训名称:{eval(Data[key][11])}</h6>
|
<h6 className='TrainTitle'>实训名称:{eval(Data[key][11])}</h6>
|
||||||
<p>关闭时间:{Data[key][6]}</p>
|
<p>关闭时间:{Data[key][6]}</p>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -43,7 +43,7 @@ function HeaderNavTeacher() {
|
||||||
</div>
|
</div>
|
||||||
<div className='left-nav-li'>
|
<div className='left-nav-li'>
|
||||||
<ul>
|
<ul>
|
||||||
{[{name:'班级管理',path:'/teacher',ImgSrc:ClassManage},{name:'实训管理',path:'/teacher/trainmanage',ImgSrc:Send},{name:'批改',path:'/teacher/mark',ImgSrc:Mark},{name:'考试管理',path:'/teacher/managetest',ImgSrc:SubjectManage},{name:'题库管理',path:'questionmange',ImgSrc:Question},{name:'设置',ImgSrc:Set,onClick:handleSettingsClick}].map((item)=>
|
{[{name:'班级管理',path:'/teacher',ImgSrc:ClassManage},{name:'实训管理',path:'/teacher/trainmanage',ImgSrc:Send},{name:'未批改',path:'/teacher/mark',ImgSrc:Mark},{name:'考试管理',path:'/teacher/managetest',ImgSrc:SubjectManage},{name:'题库管理',path:'questionmange',ImgSrc:Question},{name:'设置',ImgSrc:Set,onClick:handleSettingsClick}].map((item)=>
|
||||||
<li onClick={item.onClick}>
|
<li onClick={item.onClick}>
|
||||||
<div className='nav-li-box'>
|
<div className='nav-li-box'>
|
||||||
<Link to={item.path} className="custom-link-home" style={{color:'black'}}>
|
<Link to={item.path} className="custom-link-home" style={{color:'black'}}>
|
||||||
|
|
|
@ -15,6 +15,7 @@ function Operation2() {
|
||||||
const score=localStorage.getItem('score')
|
const score=localStorage.getItem('score')
|
||||||
const { operateID } = useParams();
|
const { operateID } = useParams();
|
||||||
const [isTrue,setisTrue]=useState(false)
|
const [isTrue,setisTrue]=useState(false)
|
||||||
|
const [TrainScore,serTrainScore]=(null)
|
||||||
|
|
||||||
const TrainData=JSON.parse(localStorage.getItem('TrainData'))
|
const TrainData=JSON.parse(localStorage.getItem('TrainData'))
|
||||||
|
|
||||||
|
@ -90,8 +91,22 @@ function Operation2() {
|
||||||
|
|
||||||
// 下拉菜单
|
// 下拉菜单
|
||||||
const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false);
|
const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false);
|
||||||
|
|
||||||
|
const submitTrain=async()=>{
|
||||||
|
try{
|
||||||
|
const submitTrainSrc=await axios.post('/api/student/EntryTrainScore',{
|
||||||
|
score,
|
||||||
|
TrainScore,
|
||||||
|
operateID,
|
||||||
|
student_ID
|
||||||
|
})
|
||||||
|
}catch{
|
||||||
|
alert('submitTrainSrc出错')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const tijiao = ()=>{
|
const tijiao = ()=>{
|
||||||
|
submitTrain()
|
||||||
setCountdown(0)
|
setCountdown(0)
|
||||||
localStorage.removeItem('time')
|
localStorage.removeItem('time')
|
||||||
localStorage.removeItem('choice_answers');
|
localStorage.removeItem('choice_answers');
|
||||||
|
@ -117,8 +132,10 @@ function Operation2() {
|
||||||
const result=detectionSrc.data['result']
|
const result=detectionSrc.data['result']
|
||||||
if(result==='NO'){
|
if(result==='NO'){
|
||||||
alert('连接失败')
|
alert('连接失败')
|
||||||
|
TrainScore(0)
|
||||||
}else{
|
}else{
|
||||||
alert('连接成功')
|
alert('连接成功')
|
||||||
|
TrainScore(50)
|
||||||
}
|
}
|
||||||
}catch{
|
}catch{
|
||||||
alert('detection出错')
|
alert('detection出错')
|
||||||
|
|
|
@ -4,7 +4,7 @@ module.exports = function(app) {
|
||||||
app.use(
|
app.use(
|
||||||
'/api', // 如果请求路径匹配'/api',则进行代理
|
'/api', // 如果请求路径匹配'/api',则进行代理
|
||||||
createProxyMiddleware({
|
createProxyMiddleware({
|
||||||
target: 'http://36.138.114.105:31055/', // 目标后端服务地址
|
target: 'http://127.0.0.1:5000', // 目标后端服务地址
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import paramiko
|
||||||
|
|
||||||
from teacher_func import *
|
from teacher_func import *
|
||||||
from student_func import *
|
from student_func import *
|
||||||
from k8s_func import *
|
# from k8s_func import *
|
||||||
|
|
||||||
from flask import Flask, render_template, request, jsonify, send_from_directory, session
|
from flask import Flask, render_template, request, jsonify, send_from_directory, session
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
@ -135,7 +135,6 @@ def fetch_result():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/student/score_entry', methods=['POST'])
|
@app.route('/api/student/score_entry', methods=['POST'])
|
||||||
def score_entry():
|
def score_entry():
|
||||||
data = request.json
|
data = request.json
|
||||||
|
@ -176,6 +175,14 @@ def FindTrain1Src():
|
||||||
result=FindTrain1SrcFunc(ID,testID)
|
result=FindTrain1SrcFunc(ID,testID)
|
||||||
return jsonify({'Src':result})
|
return jsonify({'Src':result})
|
||||||
|
|
||||||
|
@app.route('/api/student/EntryTrainScore',methods=['POST'])
|
||||||
|
def EntryTrainScore():
|
||||||
|
score=request.json['score']
|
||||||
|
TrainScore=request.json['trainScore']
|
||||||
|
operateID=request.json['operateID']
|
||||||
|
student_ID=request.json['student_ID']
|
||||||
|
AddTrainScoreFunc(score,TrainScore,student_ID,operateID)
|
||||||
|
return jsonify({'result': '成功'})
|
||||||
|
|
||||||
|
|
||||||
# 以下为教师功能—————————————————————————————————————————————————————————————————————
|
# 以下为教师功能—————————————————————————————————————————————————————————————————————
|
||||||
|
@ -294,6 +301,8 @@ def GetTrain():
|
||||||
data=getTrainFunc(teacherID)
|
data=getTrainFunc(teacherID)
|
||||||
return jsonify({'data':data})
|
return jsonify({'data':data})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/teacher/FindSrc',methods=["POST"])
|
@app.route('/api/teacher/FindSrc',methods=["POST"])
|
||||||
def FindSrc():
|
def FindSrc():
|
||||||
testID=request.json['key']
|
testID=request.json['key']
|
||||||
|
@ -329,34 +338,44 @@ def appendQuestion():
|
||||||
appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue)
|
appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue)
|
||||||
return '添加成功'
|
return '添加成功'
|
||||||
|
|
||||||
|
@app.route('/api/teacher/getTrainData',methods=["POST"])
|
||||||
|
def getTrainData():
|
||||||
|
testID=request.json['testID']
|
||||||
|
print(testID)
|
||||||
|
if testID:
|
||||||
|
data = getTrainDataFunc(testID)
|
||||||
|
return jsonify({'data': data})
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/teacher/list_pods",methods=['POST']) # 列出pod
|
|
||||||
def teacher_list_pods():
|
# @app.route("/api/teacher/list_pods",methods=['POST']) # 列出pod
|
||||||
return list_pods()
|
# def teacher_list_pods():
|
||||||
@app.route("/api/teacher/list_services") # 列出服务
|
# return list_pods()
|
||||||
def teacher_list_services():
|
# @app.route("/api/teacher/list_services") # 列出服务
|
||||||
return list_services()
|
# def teacher_list_services():
|
||||||
|
# return list_services()
|
||||||
|
|
||||||
# @app.route("/api/teacher/create_pod") # 创建服务 1为项目实训, 0为安装实训
|
# @app.route("/api/teacher/create_pod") # 创建服务 1为项目实训, 0为安装实训
|
||||||
# def teacher_create_pod():
|
# def teacher_create_pod():
|
||||||
# create_pod(1, "test2")
|
# create_pod(1, "test2")
|
||||||
|
|
||||||
@app.route("/api/teacher/DelPods",methods=['POST']) # 删除服务
|
# @app.route("/api/teacher/DelPods",methods=['POST']) # 删除服务
|
||||||
def teacher_delete_pod():
|
# def teacher_delete_pod():
|
||||||
name=request.json['name']
|
# name=request.json['name']
|
||||||
studentID=name[1:9]
|
# studentID=name[1:9]
|
||||||
testID=name[10:]
|
# testID=name[10:]
|
||||||
delDMFunc(studentID,testID)
|
# delDMFunc(studentID,testID)
|
||||||
return delete_pod(name=name)
|
# return delete_pod(name=name)
|
||||||
|
|
||||||
@app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功,返回OK 否则返回NO
|
# @app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功,返回OK 否则返回NO
|
||||||
def teacher_check_pod():
|
# def teacher_check_pod():
|
||||||
name=request.json["student_ID"]
|
# name=request.json["student_ID"]
|
||||||
testID=request.json["operateID"]
|
# testID=request.json["operateID"]
|
||||||
name= 'n' + str(name) + '-' + str(testID)
|
# name= 'n' + str(name) + '-' + str(testID)
|
||||||
result = check_dm(name)
|
# result = check_dm(name)
|
||||||
return jsonify(result)
|
# return jsonify(result)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@app.route('/<path:path>')
|
@app.route('/<path:path>')
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
import json
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
from kubernetes import client, config
|
|
||||||
from flask import jsonify
|
|
||||||
import dmPython
|
|
||||||
|
|
||||||
# Load in-cluster config
|
|
||||||
|
|
||||||
config.load_incluster_config()
|
|
||||||
v1 = client.CoreV1Api()
|
|
||||||
namespace = open("/var/run/secrets/kubernetes.io/serviceaccount/namespace").read()
|
|
||||||
IP = "36.138.114.105"
|
|
||||||
|
|
||||||
|
|
||||||
def list_pods():
|
|
||||||
ret = v1.list_namespaced_pod(namespace, watch=False)
|
|
||||||
return ({
|
|
||||||
"list": [{
|
|
||||||
"name": item.metadata.name,
|
|
||||||
"ip": item.status.pod_ip
|
|
||||||
} for item in ret.items]
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def list_services():
|
|
||||||
ret = v1.list_namespaced_service(namespace)
|
|
||||||
return {
|
|
||||||
"list": [{
|
|
||||||
"ip": item.spec.cluster_ip,
|
|
||||||
"name": item.metadata.name,
|
|
||||||
"ports": [port.to_dict() for port in item.spec.ports]
|
|
||||||
} for item in ret.items]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_pod(type, name):
|
|
||||||
# 读取 pod yaml 文件
|
|
||||||
with open(f"assets/type{type}-pod.yaml") as f:
|
|
||||||
pod_manifest = yaml.safe_load(f)
|
|
||||||
pod_manifest["metadata"]["name"] = name
|
|
||||||
pod_manifest["metadata"]["labels"]["app"] = name
|
|
||||||
# 创建 Pod
|
|
||||||
resp = v1.create_namespaced_pod(
|
|
||||||
body=pod_manifest,
|
|
||||||
namespace=namespace
|
|
||||||
)
|
|
||||||
# print(f"pod '{resp.metadata.name}' 创建成功")
|
|
||||||
# 创建 Service
|
|
||||||
with open(f"assets/type{type}-service.yaml") as f:
|
|
||||||
service_pod = yaml.safe_load(f)
|
|
||||||
service_pod["metadata"]["name"] = name + "-service"
|
|
||||||
service_pod["spec"]["selector"]["app"] = name
|
|
||||||
|
|
||||||
resp = v1.create_namespaced_service(
|
|
||||||
body=service_pod,
|
|
||||||
namespace=namespace
|
|
||||||
)
|
|
||||||
# print(f"服务 '{resp.metadata.name}' 创建成功")
|
|
||||||
if type == 1:
|
|
||||||
# 创建成功,再次查询,拿到端口
|
|
||||||
service = v1.read_namespaced_service(name=name + "-service", namespace=namespace)
|
|
||||||
# print(service)
|
|
||||||
# print("访问地址:" + IP + ":" + str(service.spec.ports[0].node_port))
|
|
||||||
else:
|
|
||||||
service = v1.read_namespaced_service(name=name + "-service", namespace=namespace)
|
|
||||||
# print(service)
|
|
||||||
# print("访问地址:" + IP + ":" + str(service.spec.ports[0].node_port))
|
|
||||||
return "cjcg"
|
|
||||||
|
|
||||||
|
|
||||||
# create_pod(0,'20240101-zt-9-0')
|
|
||||||
|
|
||||||
def delete_pod(name):
|
|
||||||
v1.delete_namespaced_pod(name=name, namespace=namespace)
|
|
||||||
print('deleting pod ' + name)
|
|
||||||
v1.delete_namespaced_service(name=name + "-service", namespace=namespace)
|
|
||||||
return "删除成功"
|
|
||||||
|
|
||||||
|
|
||||||
def check_dm(name):
|
|
||||||
try:
|
|
||||||
service = v1.read_namespaced_service(name=name + "-service", namespace=namespace)
|
|
||||||
print(service.spec.cluster_ip)
|
|
||||||
db = dmPython.connect(user='SYSDBA', password='SYSDBA', host=service.spec.cluster_ip)
|
|
||||||
cursor = db.cursor()
|
|
||||||
records = cursor.execute("SELECT * FROM V$VERSION").fetchall()
|
|
||||||
for record in records:
|
|
||||||
print(record)
|
|
||||||
return "OK"
|
|
||||||
except:
|
|
||||||
traceback.print_exc()
|
|
||||||
return "NO"
|
|
|
@ -342,6 +342,12 @@ def FindTrain1SrcFunc(ID,testID):
|
||||||
# FindTrain1SrcFunc('20240101','54')
|
# FindTrain1SrcFunc('20240101','54')
|
||||||
|
|
||||||
|
|
||||||
|
def AddTrainScoreFunc(ID,testID,score,trainResult):
|
||||||
|
cursor=db.cursor()
|
||||||
|
cursor.execute("UPDATE TRAINSCORE SET TF='true', RESULT=(?), TRAINRESULT=(?) WHERE STUDENT_ID=(?) AND TEST_ID=(?)",(score,trainResult,ID,testID))
|
||||||
|
db.commit()
|
||||||
|
cursor.close()
|
||||||
|
return '添加成功'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from Crypto.Cipher import AES
|
||||||
from Crypto.Random import get_random_bytes
|
from Crypto.Random import get_random_bytes
|
||||||
import base64
|
import base64
|
||||||
import datetime
|
import datetime
|
||||||
import k8s_func
|
# import k8s_func
|
||||||
|
|
||||||
db = dmPython.connect(user='SYSDBA', password='dameng!!', host="36.138.114.105", port="32522")
|
db = dmPython.connect(user='SYSDBA', password='dameng!!', host="36.138.114.105", port="32522")
|
||||||
|
|
||||||
|
@ -455,3 +455,11 @@ def appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue):
|
||||||
print('插入成功')
|
print('插入成功')
|
||||||
return 'INSERT'
|
return 'INSERT'
|
||||||
|
|
||||||
|
def getTrainDataFunc(testID):
|
||||||
|
cursor = db.cursor()
|
||||||
|
cursor.execute(f'SELECT * FROM TRAINSCORE WHERE TEST_ID=? ',(testID,))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
cursor.close()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue