feat: 重构前后端架构,添加Go后端和Python Agent服务
- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API - 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集 - 前端从原生HTML迁移到Vue.js框架(web/src/) - 添加 Docker Compose 支持(docker-compose.yml) - 添加项目架构文档(docs/ARCHITECTURE.md) - 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
122
server/temp_add_data2.go
Normal file
122
server/temp_add_data2.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Teacher struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Name string `gorm:"size:50;charset=utf8mb4"`
|
||||
Subject string `gorm:"size:50;charset=utf8mb4"`
|
||||
Phone string `gorm:"size:20"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Student struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Name string `gorm:"size:50;charset=utf8mb4"`
|
||||
Age int
|
||||
Gender string `gorm:"size:10;charset=utf8mb4"`
|
||||
Class string `gorm:"size:50;charset=utf8mb4"`
|
||||
Phone string `gorm:"size:20"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Score struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
StudentID uint
|
||||
Subject string `gorm:"size:50;charset=utf8mb4"`
|
||||
Score float64
|
||||
TeacherID uint
|
||||
ExamDate time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func main() {
|
||||
dsn := "root:881116142@tcp(10.10.10.189:3306)/students?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("连接数据库失败: " + err.Error())
|
||||
}
|
||||
|
||||
// 自动迁移表
|
||||
db.AutoMigrate(&Teacher{}, &Student{}, &Score{})
|
||||
|
||||
// 清理旧数据
|
||||
db.Exec("DELETE FROM scores")
|
||||
db.Exec("DELETE FROM students")
|
||||
db.Exec("DELETE FROM teachers")
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
// 创建教师
|
||||
teachers := []Teacher{
|
||||
{Name: "张老师", Subject: "数学", Phone: "13800001001"},
|
||||
{Name: "李老师", Subject: "语文", Phone: "13800001002"},
|
||||
{Name: "王老师", Subject: "英语", Phone: "13800001003"},
|
||||
{Name: "刘老师", Subject: "物理", Phone: "13800001004"},
|
||||
{Name: "陈老师", Subject: "化学", Phone: "13800001005"},
|
||||
{Name: "杨老师", Subject: "生物", Phone: "13800001006"},
|
||||
{Name: "赵老师", Subject: "历史", Phone: "13800001007"},
|
||||
{Name: "周老师", Subject: "地理", Phone: "13800001008"},
|
||||
}
|
||||
db.Create(&teachers)
|
||||
|
||||
// 创建30个学生
|
||||
names := []string{"张三", "李四", "王五", "刘六", "陈七", "杨八", "赵九", "钱十",
|
||||
"孙一", "周二", "吴三", "郑四", "冯五", "褚六", "卫七", "蒋八",
|
||||
"沈九", "韩十", "朱十一", "秦十二", "许十三", "何十四", "吕十五", "施十六",
|
||||
"张十七", "孔十八", "曹十九", "严二十", "华二十一", "金二十二"}
|
||||
genders := []string{"男", "女"}
|
||||
classes := []string{"高一(1)班", "高一(2)班", "高一(3)班", "高二(1)班", "高二(2)班"}
|
||||
|
||||
students := make([]Student, 30)
|
||||
for i := 0; i < 30; i++ {
|
||||
students[i] = Student{
|
||||
Name: names[i],
|
||||
Age: 15 + rand.Intn(3),
|
||||
Gender: genders[rand.Intn(len(genders))],
|
||||
Class: classes[rand.Intn(len(classes))],
|
||||
Phone: fmt.Sprintf("139%08d", 10000000+rand.Intn(90000000)),
|
||||
}
|
||||
}
|
||||
db.Create(&students)
|
||||
|
||||
// 为每个学生创建成绩记录
|
||||
subjects := []string{"数学", "语文", "英语", "物理", "化学", "生物", "历史", "地理"}
|
||||
scores := make([]Score, 0)
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
numSubjects := 4 + rand.Intn(3)
|
||||
selectedSubjects := make(map[string]bool)
|
||||
for len(selectedSubjects) < numSubjects {
|
||||
subj := subjects[rand.Intn(len(subjects))]
|
||||
if !selectedSubjects[subj] {
|
||||
selectedSubjects[subj] = true
|
||||
|
||||
teacherID := uint(1 + rand.Intn(len(teachers)))
|
||||
examDate := time.Now().AddDate(0, -rand.Intn(6), -rand.Intn(30))
|
||||
|
||||
score := Score{
|
||||
StudentID: students[i].ID,
|
||||
Subject: subj,
|
||||
Score: 60 + rand.Float64()*40,
|
||||
TeacherID: teacherID,
|
||||
ExamDate: examDate,
|
||||
}
|
||||
scores = append(scores, score)
|
||||
}
|
||||
}
|
||||
}
|
||||
db.Create(&scores)
|
||||
|
||||
fmt.Println("数据创建成功!")
|
||||
fmt.Printf("教师: %d 条\n", len(teachers))
|
||||
fmt.Printf("学生: %d 条\n", len(students))
|
||||
fmt.Printf("成绩: %d 条\n", len(scores))
|
||||
}
|
||||
Reference in New Issue
Block a user