"src/test/java/git@gitlab.ruzhoukj.com:wangcaixuan/rz-gb.git" did not exist on "624ee95eceb072d4c50b15f323bcb2befd544f7f"
Commit 85616b85 authored by 王蔡翾's avatar 王蔡翾
Browse files

bug修复

parent f6b4653f
-- 学员评议“撤回后重新发起”增量脚本(MySQL 5.7+/8.0)。
--
-- 原唯一索引把已撤回历史也视为重复课次。本脚本改用生成列:未撤回任务映射为subject_id,
-- 已撤回任务映射为NULL。MySQL唯一索引允许多个NULL,因此既能保留撤回历史,也能继续依靠
-- 数据库唯一约束拦截两个管理员并发发起同一课次。脚本可重复执行。
delimiter $$
drop procedure if exists migrate_evaluation_reissue$$
create procedure migrate_evaluation_reissue()
begin
if not exists (
select 1 from information_schema.tables
where table_schema = database() and table_name = 'evaluation_task'
) then
signal sqlstate '45000'
set message_text = '缺少evaluation_task表,请先执行evaluation.sql';
end if;
if not exists (
select 1 from information_schema.columns
where table_schema = database()
and table_name = 'evaluation_task'
and column_name = 'active_subject_id'
) then
alter table evaluation_task
add column active_subject_id int generated always as (
case when status = 'REVOKED' then null else subject_id end
) stored comment '未撤回任务的课次ID,用于并发防重;撤回后为NULL'
after status;
end if;
-- 先补普通索引再删除旧唯一索引,确保subject_id外键始终有可用的前导索引。
if not exists (
select 1 from information_schema.statistics
where table_schema = database()
and table_name = 'evaluation_task'
and index_name = 'idx_evaluation_task_subject'
) then
alter table evaluation_task
add index idx_evaluation_task_subject (subject_id);
end if;
if exists (
select 1 from information_schema.statistics
where table_schema = database()
and table_name = 'evaluation_task'
and index_name = 'uk_evaluation_task_subject'
) then
alter table evaluation_task
drop index uk_evaluation_task_subject;
end if;
if not exists (
select 1 from information_schema.statistics
where table_schema = database()
and table_name = 'evaluation_task'
and index_name = 'uk_evaluation_task_active_subject'
) then
alter table evaluation_task
add unique index uk_evaluation_task_active_subject (active_subject_id);
end if;
end$$
call migrate_evaluation_reissue()$$
drop procedure if exists migrate_evaluation_reissue$$
delimiter ;
-- 部署后核验:结果应为0;查询只读,不改变业务数据。
select count(*) as duplicate_non_revoked_subject_count
from (
select subject_id
from evaluation_task
where status != 'REVOKED'
group by subject_id
having count(*) > 1
) duplicate_subjects;
# 教学资源上传对接说明
## 适用课程页面交互
上传接口继续接收 `courseId`,其值是 `class_subject.id`。ID用于建立资源和具体课次的稳定关联,
页面不应要求管理员手工输入数字ID。
建议前端按以下方式实现:
1. 用 `GET /class/admin/tree` 选择班级;如页面已有职级、班级上下文,可直接复用。
2. 用 `GET /class/subject/admin/classes/{classId}` 加载该班课程。
3. 下拉框展示“课程名称 · 上课日期 · 课次”,选中项的 `id` 仅作为隐藏值保存。
4. 上传时通过 `FormData` 传入 `file`、`resourceName` 和 `courseId`,其中 `courseId` 为选中课程的 `id`。
示例:
```javascript
const form = new FormData();
form.append('file', file);
form.append('resourceName', resourceName);
form.append('courseId', String(selectedCourse.id));
```
## 大视频上传
业务服务允许单文件最大500MB,请求和Tomcat表单POST最大510MB,并以文件流落盘,不会把完整视频载入JVM堆。
110MB视频若返回HTTP 413或请求未到达业务服务,限制来自网关之前的反向代理/CDN;部署环境需将
对应入口的请求体限制同步调整到至少510MB。例如Nginx应在实际生效的 `http`、`server` 或
`location` 中配置:
```nginx
client_max_body_size 510m;
```
修改后执行 `nginx -t` 并平滑重载。若请求已到达业务服务,则同时核对Nacos远程配置是否覆盖了
`spring.servlet.multipart.max-file-size=500MB` 和
`spring.servlet.multipart.max-request-size=510MB`。前端自身的上传组件也不得保留100MB的
`beforeUpload` 限制。
package com.platform.business.sql;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** 验证撤回后重新发起所需的生成列和并发防重索引会随应用制品一起发布。 */
class EvaluationReissueMigrationSqlTest {
@Test
void migrationShouldOnlyUniquelyIndexNonRevokedTasks() throws Exception {
String sql = resource("sql/evaluation_reissue.sql").toLowerCase();
assertTrue(sql.contains("active_subject_id int generated always as"));
assertTrue(sql.contains("when status = 'revoked' then null else subject_id"));
assertTrue(sql.contains("drop index uk_evaluation_task_subject"));
assertTrue(sql.contains("unique index uk_evaluation_task_active_subject"));
}
/** 从测试资源读取SQL,确保验证的是最终打包并交付部署的迁移脚本。 */
private String resource(String path) throws Exception {
try (InputStream input = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(path)) {
assertTrue(input != null, "迁移SQL资源必须存在:" + path);
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int length;
while ((length = input.read(buffer)) >= 0) {
output.write(buffer, 0, length);
}
return new String(output.toByteArray(), StandardCharsets.UTF_8);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment