Skip to content

Commit 1762b45

Browse files
committed
feat(database): 更新课程库表结构及初始化逻辑
- 在 cs_course_library 表中添加理论、实验、实践和上机课教室类型字段 - 更新 CourseLibraryData 函数以支持新字段的初始化 - 移除冗余的版权声明,优化代码结构
1 parent b6a2f56 commit 1762b45

File tree

5 files changed

+33930
-28174
lines changed

5 files changed

+33930
-28174
lines changed

database/database_course.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* 版权所有 (c) 2022-2025 锋楪技术团队。保留所有权利。
1111
*
12-
* 本软件是按原样提供的,没有任何形式的明示或暗示的保证,包括但不限于
12+
* 本软件是"按原样"提供的,没有任何形式的明示或暗示的保证,包括但不限于
1313
* 对适销性、特定用途的适用性和非侵权性的暗示保证。在任何情况下,
1414
* 作者或版权持有人均不承担因软件或软件的使用或其他交易而产生的、
1515
* 由此引起的或以任何方式与此软件有关的任何索赔、损害或其他责任。
@@ -126,6 +126,34 @@ func (db *DbOperate) CourseLibraryData(course do.CsCourseLibrary) {
126126
db.database.Where("department_name = ?", course.Department).First(&department)
127127
course.Department = department.DepartmentUUID
128128

129+
// 检查理论课教室类型
130+
if course.TheoryClassroomType != nil {
131+
var theoryClassroomType = do.CsClassroomType{}
132+
db.database.Where("name = ?", course.TheoryClassroomType).First(&theoryClassroomType)
133+
course.TheoryClassroomType = utils.Ptr(theoryClassroomType.ClassTypeUUID)
134+
}
135+
136+
// 检查实验课教室类型
137+
if course.ExperimentClassroomType != nil {
138+
var experimentClassroomType = do.CsClassroomType{}
139+
db.database.Where("name = ?", course.ExperimentClassroomType).First(&experimentClassroomType)
140+
course.ExperimentClassroomType = utils.Ptr(experimentClassroomType.ClassTypeUUID)
141+
}
142+
143+
// 检查实践课教室类型
144+
if course.PracticeClassroomType != nil {
145+
var practiceClassroomType = do.CsClassroomType{}
146+
db.database.Where("name = ?", course.PracticeClassroomType).First(&practiceClassroomType)
147+
course.PracticeClassroomType = utils.Ptr(practiceClassroomType.ClassTypeUUID)
148+
}
149+
150+
// 检查上机课教室类型
151+
if course.ComputerClassroomType != nil {
152+
var computerClassroomType = do.CsClassroomType{}
153+
db.database.Where("name = ?", course.ComputerClassroomType).First(&computerClassroomType)
154+
course.ComputerClassroomType = utils.Ptr(computerClassroomType.ClassTypeUUID)
155+
}
156+
129157
course.CreatedAt = time.Now()
130158
course.UpdatedAt = time.Now()
131159
tx := db.database.Create(&course)

models/do/course_library_entity.go

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* 版权所有 (c) 2022-2025 锋楪技术团队。保留所有权利。
1111
*
12-
* 本软件是按原样提供的,没有任何形式的明示或暗示的保证,包括但不限于
12+
* 本软件是"按原样"提供的,没有任何形式的明示或暗示的保证,包括但不限于
1313
* 对适销性、特定用途的适用性和非侵权性的暗示保证。在任何情况下,
1414
* 作者或版权持有人均不承担因软件或软件的使用或其他交易而产生的、
1515
* 由此引起的或以任何方式与此软件有关的任何索赔、损害或其他责任。
@@ -34,35 +34,43 @@ import (
3434

3535
// CsCourseLibrary 课程库表
3636
type CsCourseLibrary struct {
37-
CourseLibraryUUID string `gorm:"type:char(32);primaryKey;comment:课程库主键"`
38-
ID string `gorm:"type:varchar(32);unique;not null;comment:课程编号"`
39-
Name string `gorm:"type:varchar(32);unique;not null;comment:课程库名称"`
40-
EnglishName *string `gorm:"type:varchar(128);not null;comment:课程英文名称"`
41-
Category *string `gorm:"type:char(32);not null;comment:课程类别"`
42-
Property *string `gorm:"type:char(32);not null;comment:课程属性"`
43-
Type string `gorm:"type:char(32);not null;comment:课程类型"`
44-
Nature *string `gorm:"type:char(32);not null;comment:课程性质"`
45-
Department string `gorm:"type:char(32);not null;comment:开课学院"`
46-
IsEnabled bool `gorm:"type:tinyint(1);default:1;not null;comment:是否启用"`
47-
TotalHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:总学时"`
48-
WeekHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:周学时"`
49-
TheoryHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:理论学时"`
50-
ExperimentHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:实验学时"`
51-
PracticeHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:实践学时"`
52-
ComputerHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:上机学时"`
53-
OtherHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:其他学时"`
54-
Credit float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:学分"`
55-
Description string `gorm:"type:text;comment:课程库描述"`
56-
EditUser *string `gorm:"type:char(32);comment:编辑人"`
57-
CreatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null;comment:创建时间"`
58-
UpdatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;not null;comment:更新时间"`
37+
CourseLibraryUUID string `gorm:"type:char(32);primaryKey;comment:课程库主键"`
38+
ID string `gorm:"type:varchar(32);unique;not null;comment:课程编号"`
39+
Name string `gorm:"type:varchar(32);unique;not null;comment:课程库名称"`
40+
EnglishName *string `gorm:"type:varchar(128);not null;comment:课程英文名称"`
41+
Category *string `gorm:"type:char(32);not null;comment:课程类别"`
42+
Property *string `gorm:"type:char(32);not null;comment:课程属性"`
43+
Type string `gorm:"type:char(32);not null;comment:课程类型"`
44+
Nature *string `gorm:"type:char(32);not null;comment:课程性质"`
45+
Department string `gorm:"type:char(32);not null;comment:开课学院"`
46+
IsEnabled bool `gorm:"type:tinyint(1);default:1;not null;comment:是否启用"`
47+
TotalHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:总学时"`
48+
WeekHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:周学时"`
49+
TheoryHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:理论学时"`
50+
ExperimentHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:实验学时"`
51+
PracticeHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:实践学时"`
52+
ComputerHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:上机学时"`
53+
OtherHours float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:其他学时"`
54+
Credit float64 `gorm:"type:decimal(10,2);default:0.00;not null;comment:学分"`
55+
TheoryClassroomType *string `gorm:"type:char(32);comment:理论课教室类型"`
56+
ExperimentClassroomType *string `gorm:"type:char(32);comment:实验课教室类型"`
57+
PracticeClassroomType *string `gorm:"type:char(32);comment:实践课教室类型"`
58+
ComputerClassroomType *string `gorm:"type:char(32);comment:上机课教室类型"`
59+
Description string `gorm:"type:text;comment:课程库描述"`
60+
EditUser *string `gorm:"type:char(32);comment:编辑人"`
61+
CreatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null;comment:创建时间"`
62+
UpdatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;not null;comment:更新时间"`
5963

6064
// 外键关联
61-
CategoryRel CsCourseCategory `gorm:"foreignKey:Category;references:CourseCategoryUUID"`
62-
PropertyRel CsCourseProperty `gorm:"foreignKey:Property;references:CoursePropertyUUID"`
63-
TypeRel CsCourseType `gorm:"foreignKey:Type;references:CourseTypeUUID"`
64-
NatureRel CsCourseNature `gorm:"foreignKey:Nature;references:CourseNatureUUID"`
65-
DepartmentRel CsDepartment `gorm:"foreignKey:Department;references:DepartmentUUID"`
65+
CategoryRel CsCourseCategory `gorm:"foreignKey:Category;references:CourseCategoryUUID"`
66+
PropertyRel CsCourseProperty `gorm:"foreignKey:Property;references:CoursePropertyUUID"`
67+
TypeRel CsCourseType `gorm:"foreignKey:Type;references:CourseTypeUUID"`
68+
NatureRel CsCourseNature `gorm:"foreignKey:Nature;references:CourseNatureUUID"`
69+
DepartmentRel CsDepartment `gorm:"foreignKey:Department;references:DepartmentUUID"`
70+
TheoryClassroomTypeRel CsClassroomType `gorm:"foreignKey:TheoryClassroomType;references:ClassTypeUUID"`
71+
ExperimentClassroomTypeRel CsClassroomType `gorm:"foreignKey:ExperimentClassroomType;references:ClassTypeUUID"`
72+
PracticeClassroomTypeRel CsClassroomType `gorm:"foreignKey:PracticeClassroomType;references:ClassTypeUUID"`
73+
ComputerClassroomTypeRel CsClassroomType `gorm:"foreignKey:ComputerClassroomType;references:ClassTypeUUID"`
6674
}
6775

6876
// TableName 指定表名

process_course.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import re
2+
import random
3+
4+
def get_theory_classroom_type(course_name, course_type):
5+
# 根据课程名称和类型选择合适的理论课教室
6+
special_rooms = {
7+
"音乐": "琴房",
8+
"舞蹈": "舞蹈教室",
9+
"美术": "美术教室",
10+
"声乐": "声乐教室",
11+
}
12+
13+
for keyword, room in special_rooms.items():
14+
if keyword in course_name:
15+
return room
16+
17+
# 随机选择普通教室或多媒体教室
18+
return random.choice(["普通教室", "多媒体教室"])
19+
20+
def get_experiment_classroom_type(course_name, course_type):
21+
# 根据课程名称和类型选择合适的实验课教室
22+
special_rooms = {
23+
"化工": "化工仿真实训室",
24+
"仿真": "虚拟仿真实训室",
25+
"自动化": "自动化生产线实训室",
26+
"液压": "液压气动实训室",
27+
"电工": "电工实训室",
28+
"网络": "网络实训室",
29+
"幼儿": "幼儿保健室",
30+
"机械": "机械装调实训室",
31+
"汽修": "汽修实训室",
32+
}
33+
34+
for keyword, room in special_rooms.items():
35+
if keyword in course_name:
36+
return room
37+
38+
return "实训车间"
39+
40+
def get_practice_classroom_type(course_name, course_type):
41+
# 根据课程名称和类型选择合适的实践课教室
42+
special_rooms = {
43+
"网络": "网络综合布线室",
44+
"幼儿": "蒙台梭立实训室",
45+
"活动": "活动室",
46+
"电气": "现代电气控制实训室",
47+
}
48+
49+
for keyword, room in special_rooms.items():
50+
if keyword in course_name:
51+
return room
52+
53+
return "实训车间"
54+
55+
def process_course_data(input_file, output_file):
56+
with open(input_file, 'r', encoding='utf-8') as f:
57+
content = f.read()
58+
59+
# 找到所有的课程数据块
60+
pattern = r'is\.operate\.CourseLibraryData\(do\.CsCourseLibrary\{([^}]+)\}\)'
61+
course_blocks = list(re.finditer(pattern, content))
62+
63+
for block in course_blocks:
64+
course_data = block.group(1)
65+
original_data = course_data
66+
67+
# 提取课程信息
68+
name_match = re.search(r'Name:\s*"([^"]+)"', course_data)
69+
type_match = re.search(r'Type:\s*"([^"]+)"', course_data)
70+
course_name = name_match.group(1) if name_match else ""
71+
course_type = type_match.group(1) if type_match else ""
72+
73+
# 提取各种学时
74+
theory_hours = re.search(r'TheoryHours:\s*(\d+)', course_data)
75+
experiment_hours = re.search(r'ExperimentHours:\s*(\d+)', course_data)
76+
practice_hours = re.search(r'PracticeHours:\s*(\d+)', course_data)
77+
computer_hours = re.search(r'ComputerHours:\s*(\d+)', course_data)
78+
credit_match = re.search(r'Credit:\s*([\d.]+)', course_data)
79+
credit = credit_match.group(1) if credit_match else "0"
80+
81+
# 准备新的字段
82+
new_fields = []
83+
if theory_hours and int(theory_hours.group(1)) > 0:
84+
classroom = get_theory_classroom_type(course_name, course_type)
85+
new_fields.append(f'TheoryClassroomType: utils.Ptr("{classroom}"),')
86+
else:
87+
new_fields.append('TheoryClassroomType: nil,')
88+
89+
if experiment_hours and int(experiment_hours.group(1)) > 0:
90+
classroom = get_experiment_classroom_type(course_name, course_type)
91+
new_fields.append(f'ExperimentClassroomType: utils.Ptr("{classroom}"),')
92+
else:
93+
new_fields.append('ExperimentClassroomType: nil,')
94+
95+
if practice_hours and int(practice_hours.group(1)) > 0:
96+
classroom = get_practice_classroom_type(course_name, course_type)
97+
new_fields.append(f'PracticeClassroomType: utils.Ptr("{classroom}"),')
98+
else:
99+
new_fields.append('PracticeClassroomType: nil,')
100+
101+
if computer_hours and int(computer_hours.group(1)) > 0:
102+
new_fields.append(f'ComputerClassroomType: utils.Ptr("机房"),')
103+
else:
104+
new_fields.append('ComputerClassroomType: nil,')
105+
106+
# 删除已存在的教室类型字段
107+
course_data = re.sub(r'\s*TheoryClassroomType:\s*[^,]+,', '', course_data)
108+
course_data = re.sub(r'\s*ExperimentClassroomType:\s*[^,]+,', '', course_data)
109+
course_data = re.sub(r'\s*PracticeClassroomType:\s*[^,]+,', '', course_data)
110+
course_data = re.sub(r'\s*ComputerClassroomType:\s*[^,]+,', '', course_data)
111+
112+
# 在 Credit 后添加新字段
113+
new_fields_str = '\n\t\t' + '\n\t\t'.join(new_fields)
114+
course_data = re.sub(r'Credit:\s*[\d.]+,?', f'Credit: {credit},', course_data)
115+
new_content = re.sub(r'Credit:\s*[\d.]+,?', f'Credit: {credit},{new_fields_str}', course_data)
116+
content = content.replace(original_data, new_content)
117+
118+
with open(output_file, 'w', encoding='utf-8') as f:
119+
f.write(content)
120+
121+
# 处理文件
122+
input_file = '/Users/xiaolfeng/ProgramProjects/Enterprise/FrontLeaves/ClassSchedulingSystem/table-install-cli/services/setup/setup_course.go'
123+
output_file = '/Users/xiaolfeng/ProgramProjects/Enterprise/FrontLeaves/ClassSchedulingSystem/table-install-cli/services/setup/setup_course_new.go'
124+
process_course_data(input_file, output_file)

resources/sql/cs_class_assignment.sql

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,6 @@
2626
* --------------------------------------------------------------------------------
2727
*/
2828

29-
/*
30-
* --------------------------------------------------------------------------------
31-
* Copyright (c) 2022-NOW(至今) 锋楪技术团队
32-
* Author: 锋楪技术团队 (https://www.frontleaves.com)
33-
*
34-
* 本文件包含锋楪技术团队项目的源代码,项目的所有源代码均遵循 MIT 开源许可证协议。
35-
* --------------------------------------------------------------------------------
36-
* 许可证声明:
37-
*
38-
* 版权所有 (c) 2022-2025 锋楪技术团队。保留所有权利。
39-
*
40-
* 本软件是“按原样”提供的,没有任何形式的明示或暗示的保证,包括但不限于
41-
* 对适销性、特定用途的适用性和非侵权性的暗示保证。在任何情况下,
42-
* 作者或版权持有人均不承担因软件或软件的使用或其他交易而产生的、
43-
* 由此引起的或以任何方式与此软件有关的任何索赔、损害或其他责任。
44-
*
45-
* 使用本软件即表示您了解此声明并同意其条款。
46-
*
47-
* 有关 MIT 许可证的更多信息,请查看项目根目录下的 LICENSE 文件或访问:
48-
* https://opensource.org/licenses/MIT
49-
* --------------------------------------------------------------------------------
50-
* 免责声明:
51-
*
52-
* 使用本软件的风险由用户自担。作者或版权持有人在法律允许的最大范围内,
53-
* 对因使用本软件内容而导致的任何直接或间接的损失不承担任何责任。
54-
* --------------------------------------------------------------------------------
55-
*/
56-
5729
USE `class-scheduling-system`;
5830
CREATE TABLE `cs_class_assignment`
5931
(

0 commit comments

Comments
 (0)