This commit is contained in:
30404 2024-07-10 12:49:06 +08:00
parent 99b6db2138
commit defc9a5714
9 changed files with 97 additions and 130 deletions

View File

@ -11,10 +11,9 @@ function TrainPods(){
const FindPodsFunc=await axios.post('/api/teacher/list_pods')
setPods(FindPodsFunc.data)
}catch{
alert('出错')
}
}
useEffect(()=>{
FindPodsFunc()
},[])
@ -25,8 +24,7 @@ function TrainPods(){
name,
})
alert('删除成功')
// eslint-disable-next-line no-restricted-globals
location.reload();
window.location.reload();
}catch{
alert('出错')
}
@ -42,11 +40,9 @@ function TrainPods(){
setSrcData(FindSrcc.data['data'])
setisTrue(false)
}catch{
alert('SrcDAta出错')
alert('SrcData出错')
}
}
// // eslint-disable-next-line no-restricted-globals
//
return(
<div className='body-right-Pods'>
@ -93,9 +89,6 @@ function TrainPods(){
</div>
<button onClick={()=>setisTrue(!isTrue)} style={{marginLeft:'600px'}} className='srcbtn'>返回</button>
</table>}
<button onClick={()=>{
console.log(Pods);
}}></button>
</div>
)
}

View File

@ -8,6 +8,8 @@ import React, { useEffect, useState } from 'react';
function TrainManage(){
const teacher_ID=localStorage.getItem('islogin')
const [Data,setData]=useState()
const [testID,settestID]=useState()
const [TrainData,setTrainData]=useState()
//
const getTrainfunc=async()=>{
try{
@ -23,6 +25,22 @@ function TrainManage(){
useEffect(()=>{
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(
<div className='body-trainmanage'>
<p className='title'>已结束的实训</p>

View File

@ -43,7 +43,7 @@ function HeaderNavTeacher() {
</div>
<div className='left-nav-li'>
<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}>
<div className='nav-li-box'>
<Link to={item.path} className="custom-link-home" style={{color:'black'}}>

View File

@ -15,6 +15,7 @@ function Operation2() {
const score=localStorage.getItem('score')
const { operateID } = useParams();
const [isTrue,setisTrue]=useState(false)
const [TrainScore,serTrainScore]=(null)
const TrainData=JSON.parse(localStorage.getItem('TrainData'))
@ -91,7 +92,21 @@ function Operation2() {
//
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 = ()=>{
submitTrain()
setCountdown(0)
localStorage.removeItem('time')
localStorage.removeItem('choice_answers');
@ -117,8 +132,10 @@ function Operation2() {
const result=detectionSrc.data['result']
if(result==='NO'){
alert('连接失败')
TrainScore(0)
}else{
alert('连接成功')
TrainScore(50)
}
}catch{
alert('detection出错')

View File

@ -4,7 +4,7 @@ module.exports = function(app) {
app.use(
'/api', // 如果请求路径匹配'/api',则进行代理
createProxyMiddleware({
target: 'http://36.138.114.105:31055/', // 目标后端服务地址
target: 'http://127.0.0.1:5000', // 目标后端服务地址
changeOrigin: true,
})
);

View File

@ -6,7 +6,7 @@ import paramiko
from teacher_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_cors import CORS
@ -135,7 +135,6 @@ def fetch_result():
@app.route('/api/student/score_entry', methods=['POST'])
def score_entry():
data = request.json
@ -176,6 +175,14 @@ def FindTrain1Src():
result=FindTrain1SrcFunc(ID,testID)
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)
return jsonify({'data':data})
@app.route('/api/teacher/FindSrc',methods=["POST"])
def FindSrc():
testID=request.json['key']
@ -329,34 +338,44 @@ def appendQuestion():
appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue)
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():
return list_pods()
@app.route("/api/teacher/list_services") # 列出服务
def teacher_list_services():
return list_services()
# @app.route("/api/teacher/list_pods",methods=['POST']) # 列出pod
# def teacher_list_pods():
# return list_pods()
# @app.route("/api/teacher/list_services") # 列出服务
# def teacher_list_services():
# return list_services()
# @app.route("/api/teacher/create_pod") # 创建服务 1为项目实训 0为安装实训
# def teacher_create_pod():
# create_pod(1, "test2")
@app.route("/api/teacher/DelPods",methods=['POST']) # 删除服务
def teacher_delete_pod():
name=request.json['name']
studentID=name[1:9]
testID=name[10:]
delDMFunc(studentID,testID)
return delete_pod(name=name)
# @app.route("/api/teacher/DelPods",methods=['POST']) # 删除服务
# def teacher_delete_pod():
# name=request.json['name']
# studentID=name[1:9]
# testID=name[10:]
# delDMFunc(studentID,testID)
# return delete_pod(name=name)
@app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功返回OK 否则返回NO
def teacher_check_pod():
name=request.json["student_ID"]
testID=request.json["operateID"]
name= 'n' + str(name) + '-' + str(testID)
result = check_dm(name)
return jsonify(result)
# @app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功返回OK 否则返回NO
# def teacher_check_pod():
# name=request.json["student_ID"]
# testID=request.json["operateID"]
# name= 'n' + str(name) + '-' + str(testID)
# result = check_dm(name)
# return jsonify(result)
@app.route('/')
@app.route('/<path:path>')

View File

@ -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"

View File

@ -342,6 +342,12 @@ def FindTrain1SrcFunc(ID,testID):
# 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 '添加成功'

View File

@ -4,7 +4,7 @@ from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import base64
import datetime
import k8s_func
# import k8s_func
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('插入成功')
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