Commit 64e183dc authored by wujipeng's avatar wujipeng
Browse files

bug修复

parent bb7667c7
package com.platform.business.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/** 管理端理论练习列表的等级筛选选项。 */
@Data
public class TheoreticalPracticeLevelOptionVO {
/**
* 提交给分页接口 {@code lev} 字段的值。
*
* <p>该值直接来源于已有理论练习数据,而不是班级树的某一条分支,因此历史练习、
* 技能竞赛以及分散在不同工种和学年下的等级都能被完整筛选。</p>
*/
@ApiModelProperty("等级筛选值")
private String value;
/** 页面下拉框展示的等级名称。 */
@ApiModelProperty("等级展示名称")
private String label;
}
...@@ -23,12 +23,12 @@ public class TheoreticalPracticeVO extends TheoreticalPracticeEntity { ...@@ -23,12 +23,12 @@ public class TheoreticalPracticeVO extends TheoreticalPracticeEntity {
@ApiModelProperty(value = "人数") @ApiModelProperty(value = "人数")
private String studentCount; private String studentCount;
@ApiModelProperty(value = "状态") @ApiModelProperty(value = "状态:未开始/进行中/已结束")
private String status; private String status;
/** /**
* 供前端筛选和样式判断使用的稳定状态码。保留status中文文案以兼容旧页面, * 供前端筛选和样式判断使用的稳定状态码。status与状态码保持一一对应,
* 新页面应优先使用PENDING、ONGOING、ENDED三个状态码。 * 页面应优先使用PENDING、ONGOING、ENDED三个状态码进行逻辑判断。
*/ */
@ApiModelProperty(value = "状态码:PENDING/ONGOING/ENDED") @ApiModelProperty(value = "状态码:PENDING/ONGOING/ENDED")
private String statusCode; private String statusCode;
......
...@@ -12,6 +12,14 @@ public final class TheoreticalPracticeConstants { ...@@ -12,6 +12,14 @@ public final class TheoreticalPracticeConstants {
public static final String STATUS_ONGOING = "ONGOING"; public static final String STATUS_ONGOING = "ONGOING";
public static final String STATUS_ENDED = "ENDED"; public static final String STATUS_ENDED = "ENDED";
/**
* 管理端列表统一使用产品定义的三态文案。手动关闭只影响状态判定,
* 对外仍展示“已结束”,避免同一个ENDED状态码对应两种列表文案。
*/
public static final String STATUS_LABEL_PENDING = "未开始";
public static final String STATUS_LABEL_ONGOING = "进行中";
public static final String STATUS_LABEL_ENDED = "已结束";
public static final String STUDENT_NOT_STARTED = "NOT_STARTED"; public static final String STUDENT_NOT_STARTED = "NOT_STARTED";
public static final String STUDENT_EXCELLENT = "EXCELLENT"; public static final String STUDENT_EXCELLENT = "EXCELLENT";
public static final String STUDENT_GOOD = "GOOD"; public static final String STUDENT_GOOD = "GOOD";
......
...@@ -4,6 +4,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO; ...@@ -4,6 +4,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO; import com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO;
import com.platform.business.model.entity.UserEntity; import com.platform.business.model.entity.UserEntity;
import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO; import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO;
import com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO;
import com.platform.business.model.vo.TheoreticalPracticeSummaryVO; import com.platform.business.model.vo.TheoreticalPracticeSummaryVO;
import com.platform.business.model.vo.TheoreticalPracticeVO; import com.platform.business.model.vo.TheoreticalPracticeVO;
...@@ -20,6 +21,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -20,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List;
/** /**
...@@ -55,6 +57,13 @@ public class TheoreticalPracticeController extends BaseController { ...@@ -55,6 +57,13 @@ public class TheoreticalPracticeController extends BaseController {
return getDataTable(theoreticalPracticeService.page(theoreticalPracticeDTO)); return getDataTable(theoreticalPracticeService.page(theoreticalPracticeDTO));
} }
@ApiOperation("理论练习列表完整等级筛选项")
@GetMapping("/levels")
public Result<List<TheoreticalPracticeLevelOptionVO>> levels(HttpServletRequest request) {
requireAdmin(request);
return Result.data(theoreticalPracticeService.levelOptions());
}
@ApiOperation("一级页面练习总数、进行中和已结束统计") @ApiOperation("一级页面练习总数、进行中和已结束统计")
@GetMapping("/summary") @GetMapping("/summary")
public Result<TheoreticalPracticeSummaryVO> summary(HttpServletRequest request) { public Result<TheoreticalPracticeSummaryVO> summary(HttpServletRequest request) {
......
...@@ -22,9 +22,14 @@ public interface ClassMapper extends BaseMapper<ClassEntity> { ...@@ -22,9 +22,14 @@ public interface ClassMapper extends BaseMapper<ClassEntity> {
List<ClassVO> queryList(ClassDTO classDTO); List<ClassVO> queryList(ClassDTO classDTO);
/** 管理员卡片分页和导航树复用同一套过滤条件。 */ /**
* 管理员卡片分页和导航树复用同一套过滤条件。
*
* @param orderByCreateTime true时按创建时间倒序返回卡片列表;false时保留导航树所需的分组顺序
*/
List<ClassAdminCardVO> selectAdminClasses(@Param("query") ClassAdminQueryDTO query, List<ClassAdminCardVO> selectAdminClasses(@Param("query") ClassAdminQueryDTO query,
@Param("today") Date today); @Param("today") Date today,
@Param("orderByCreateTime") boolean orderByCreateTime);
ClassAdminDetailVO selectAdminDetail(@Param("classId") Integer classId); ClassAdminDetailVO selectAdminDetail(@Param("classId") Integer classId);
......
...@@ -5,6 +5,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO; ...@@ -5,6 +5,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import com.platform.business.model.entity.TheoreticalPracticeEntity; import com.platform.business.model.entity.TheoreticalPracticeEntity;
import com.platform.business.model.vo.TheoreticalPracticeVO; import com.platform.business.model.vo.TheoreticalPracticeVO;
import com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO;
import com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO;
import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO; import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO;
import com.platform.business.model.vo.TheoreticalPracticeSummaryVO; import com.platform.business.model.vo.TheoreticalPracticeSummaryVO;
...@@ -26,6 +27,11 @@ public interface TheoreticalPracticeMapper extends BaseMapper<TheoreticalPractic ...@@ -26,6 +27,11 @@ public interface TheoreticalPracticeMapper extends BaseMapper<TheoreticalPractic
List<TheoreticalPracticeVO> page(@Param("query") TheoreticalPracticeDTO theoreticalPracticeDTO, List<TheoreticalPracticeVO> page(@Param("query") TheoreticalPracticeDTO theoreticalPracticeDTO,
@Param("now") Date now); @Param("now") Date now);
/**
* 从理论练习自身的数据全集提取等级,避免通过班级导航树取值时只遍历到部分分支。
*/
List<TheoreticalPracticeLevelOptionVO> selectLevelOptions();
TheoreticalPracticeVO detail(@Param("id") String id); TheoreticalPracticeVO detail(@Param("id") String id);
TheoreticalPracticeSummaryVO summary(@Param("now") Date now); TheoreticalPracticeSummaryVO summary(@Param("now") Date now);
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.business.model.dto.TheoreticalPracticeDTO; import com.platform.business.model.dto.TheoreticalPracticeDTO;
import com.platform.business.model.entity.TheoreticalPracticeEntity; import com.platform.business.model.entity.TheoreticalPracticeEntity;
import com.platform.business.model.vo.TheoreticalPracticeVO; import com.platform.business.model.vo.TheoreticalPracticeVO;
import com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO;
import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO; import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO;
...@@ -24,6 +25,9 @@ import java.util.List; ...@@ -24,6 +25,9 @@ import java.util.List;
public interface TheoreticalPracticeService extends IService<TheoreticalPracticeEntity> { public interface TheoreticalPracticeService extends IService<TheoreticalPracticeEntity> {
List<TheoreticalPracticeVO> page(TheoreticalPracticeDTO theoreticalPracticeDTO); List<TheoreticalPracticeVO> page(TheoreticalPracticeDTO theoreticalPracticeDTO);
/** 返回一级列表全部可筛选的等级,选项来源与列表数据保持一致。 */
List<TheoreticalPracticeLevelOptionVO> levelOptions();
TheoreticalPracticeVO detail(String id); TheoreticalPracticeVO detail(String id);
Result<Boolean> saveOrUpdateData(TheoreticalPracticeDTO theoreticalPracticeDTO); Result<Boolean> saveOrUpdateData(TheoreticalPracticeDTO theoreticalPracticeDTO);
......
...@@ -64,7 +64,9 @@ public class ClassAdminServiceImpl implements ClassAdminService { ...@@ -64,7 +64,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
public List<ClassAdminCardVO> page(ClassAdminQueryDTO query) { public List<ClassAdminCardVO> page(ClassAdminQueryDTO query) {
ClassAdminQueryDTO normalized = query == null ? new ClassAdminQueryDTO() : query; ClassAdminQueryDTO normalized = query == null ? new ClassAdminQueryDTO() : query;
normalizeQuery(normalized); normalizeQuery(normalized);
List<ClassAdminCardVO> classes = classMapper.selectAdminClasses(normalized, businessSqlDate()); // 卡片分页必须在数据库分页前完成创建时间排序,确保跨页、筛选和搜索时顺序始终一致。
List<ClassAdminCardVO> classes = classMapper.selectAdminClasses(
normalized, businessSqlDate(), true);
LocalDate today = businessToday(); LocalDate today = businessToday();
classes.forEach(item -> applyClassStatus(item, today)); classes.forEach(item -> applyClassStatus(item, today));
return classes; return classes;
...@@ -75,7 +77,9 @@ public class ClassAdminServiceImpl implements ClassAdminService { ...@@ -75,7 +77,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
ClassAdminQueryDTO query = new ClassAdminQueryDTO(); ClassAdminQueryDTO query = new ClassAdminQueryDTO();
query.setKeyword(keyword); query.setKeyword(keyword);
normalizeQuery(query); normalizeQuery(query);
List<ClassAdminCardVO> classes = classMapper.selectAdminClasses(query, businessSqlDate()); // 导航树仍按年度、工种和等级分组排序,避免卡片排序需求改变左侧树的既有结构。
List<ClassAdminCardVO> classes = classMapper.selectAdminClasses(
query, businessSqlDate(), false);
return buildTree(classes); return buildTree(classes);
} }
......
...@@ -412,7 +412,7 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe ...@@ -412,7 +412,7 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
if (!TheoreticalPaperAdminConstants.QUESTION_TYPES.contains(type)) { if (!TheoreticalPaperAdminConstants.QUESTION_TYPES.contains(type)) {
throw new BusinessException(prefix + "题型只支持判断题、单选题、多选题或主观题"); throw new BusinessException(prefix + "题型只支持判断题、单选题、多选题或主观题");
} }
String problem = requireText(input.getProblem(), 4000, prefix + "题干"); String problem = normalizeQuestionProblem(input, prefix);
String answer = requireText(input.getAnswer(), 4000, prefix + "答案"); String answer = requireText(input.getAnswer(), 4000, prefix + "答案");
BigDecimal score = decimal(input.getScore(), prefix + "分值"); BigDecimal score = decimal(input.getScore(), prefix + "分值");
if (score.compareTo(BigDecimal.ZERO) <= 0 || score.compareTo(new BigDecimal("1000")) > 0) { if (score.compareTo(BigDecimal.ZERO) <= 0 || score.compareTo(new BigDecimal("1000")) > 0) {
...@@ -456,6 +456,59 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe ...@@ -456,6 +456,59 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
return target; return target;
} }
/**
* 取得可直接写入试卷明细表的纯题干。
*
* <p>旧版题库分页接口为了方便页面展示,会把选择题格式化成
* “题干\nA.选项A\nB.选项B...”后放回 {@code problem},同时又保留独立的
* {@code optionA-optionE} 字段。手动组卷页面把该对象原样提交后,如果继续保存这个
* 展示字符串,不但预览时会重复显示选项,还可能超过试卷明细表 {@code problem}
* 的128字符限制并触发数据库异常,最终表现为保存草稿和发布均返回500。</p>
*
* <p>这里只在题干末尾与独立选项能逐字对应时剥离旧版展示后缀,避免误删用户题干中
* 正常出现的“A.”等文本。兼容前端保留或去掉末尾换行的两种提交形式;清洗完成后再按
* 当前数据库真实长度校验,使异常输入返回明确业务提示,而不是进入数据库后报500。</p>
*/
private String normalizeQuestionProblem(TheoreticalPaperDetailEntity question, String prefix) {
String submitted = requireText(question.getProblem(), 4000, prefix + "题干");
String normalizedLineBreaks = submitted.replace("\r\n", "\n").replace('\r', '\n');
String legacyOptionSuffix = buildLegacyOptionSuffix(question);
if (legacyOptionSuffix != null) {
String suffixWithTrailingLineBreak = "\n" + legacyOptionSuffix;
String suffixWithoutTrailingLineBreak = suffixWithTrailingLineBreak.substring(
0, suffixWithTrailingLineBreak.length() - 1);
if (normalizedLineBreaks.endsWith(suffixWithTrailingLineBreak)) {
normalizedLineBreaks = normalizedLineBreaks.substring(
0, normalizedLineBreaks.length() - suffixWithTrailingLineBreak.length());
} else if (normalizedLineBreaks.endsWith(suffixWithoutTrailingLineBreak)) {
normalizedLineBreaks = normalizedLineBreaks.substring(
0, normalizedLineBreaks.length() - suffixWithoutTrailingLineBreak.length());
}
}
return requireText(normalizedLineBreaks, 128, prefix + "题干");
}
/**
* 按旧版 {@code TheoreticalLibraryMapper.pageData} 完全相同的格式重建选项后缀。
* 使用“非null”而非“非空”判断,是为了与旧SQL中的 {@code IS NOT NULL} 保持一致。
*/
private String buildLegacyOptionSuffix(TheoreticalPaperDetailEntity question) {
StringBuilder suffix = new StringBuilder();
appendLegacyOption(suffix, 'A', question.getOptionA());
appendLegacyOption(suffix, 'B', question.getOptionB());
appendLegacyOption(suffix, 'C', question.getOptionC());
appendLegacyOption(suffix, 'D', question.getOptionD());
appendLegacyOption(suffix, 'E', question.getOptionE());
return suffix.length() == 0 ? null : suffix.toString();
}
/** 每个旧版展示选项固定以“字母.内容\n”拼接,末尾同样保留换行。 */
private void appendLegacyOption(StringBuilder suffix, char label, String option) {
if (option != null) {
suffix.append(label).append('.').append(option).append('\n');
}
}
private String normalizeAnswer(String type, String answer, private String normalizeAnswer(String type, String answer,
TheoreticalPaperDetailEntity question, String prefix) { TheoreticalPaperDetailEntity question, String prefix) {
if ("单选题".equals(type)) { if ("单选题".equals(type)) {
......
...@@ -10,6 +10,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO; ...@@ -10,6 +10,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO; import com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO;
import com.platform.business.model.entity.*; import com.platform.business.model.entity.*;
import com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO;
import com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO;
import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO; import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO;
...@@ -76,27 +77,37 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract ...@@ -76,27 +77,37 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract
TheoreticalPracticeDTO safeQuery = normalizePageQuery(theoreticalPracticeDTO); TheoreticalPracticeDTO safeQuery = normalizePageQuery(theoreticalPracticeDTO);
Date now = new Date(); Date now = new Date();
List<TheoreticalPracticeVO> result = baseMapper.page(safeQuery, now); List<TheoreticalPracticeVO> result = baseMapper.page(safeQuery, now);
// 中文状态继续兼容旧页面,同时补充稳定状态码供新筛选项和样式判断使用。 // 列表按产品定义统一为“未开始、进行中、已结束”三态;手动关闭也归入已结束。
for (TheoreticalPracticeVO theoreticalPracticeVO : result) { for (TheoreticalPracticeVO theoreticalPracticeVO : result) {
if (Boolean.TRUE.equals(theoreticalPracticeVO.getIsClose())) { if (Boolean.TRUE.equals(theoreticalPracticeVO.getIsClose())) {
theoreticalPracticeVO.setStatus("已手动关闭"); theoreticalPracticeVO.setStatus(TheoreticalPracticeConstants.STATUS_LABEL_ENDED);
theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_ENDED); theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_ENDED);
continue; continue;
} }
if (theoreticalPracticeVO.getStartTime().after(now)) { if (theoreticalPracticeVO.getStartTime().after(now)) {
theoreticalPracticeVO.setStatus("未开放"); theoreticalPracticeVO.setStatus(TheoreticalPracticeConstants.STATUS_LABEL_PENDING);
theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_PENDING); theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_PENDING);
} else if (theoreticalPracticeVO.getEndTime().before(now)) { } else if (theoreticalPracticeVO.getEndTime().before(now)) {
theoreticalPracticeVO.setStatus("已结束"); theoreticalPracticeVO.setStatus(TheoreticalPracticeConstants.STATUS_LABEL_ENDED);
theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_ENDED); theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_ENDED);
} else { } else {
theoreticalPracticeVO.setStatus("已开放"); theoreticalPracticeVO.setStatus(TheoreticalPracticeConstants.STATUS_LABEL_ONGOING);
theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_ONGOING); theoreticalPracticeVO.setStatusCode(TheoreticalPracticeConstants.STATUS_ONGOING);
} }
} }
return result; return result;
} }
/**
* 筛选选项直接由理论练习表聚合,确保页面中出现过的每一个等级都可被筛选。
* 班级导航树按“工种-学年-等级”分支组织,不适合作为扁平等级下拉框的数据源。
*/
@Override
@Transactional(readOnly = true)
public List<TheoreticalPracticeLevelOptionVO> levelOptions() {
return baseMapper.selectLevelOptions();
}
@Override @Override
public TheoreticalPracticeVO detail(String id) { public TheoreticalPracticeVO detail(String id) {
List<TheoreticalPracticeStudentVO> studentList = theoreticalPracticeStudentService.selectStudentListByPracticeId(id); List<TheoreticalPracticeStudentVO> studentList = theoreticalPracticeStudentService.selectStudentListByPracticeId(id);
...@@ -302,6 +313,12 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract ...@@ -302,6 +313,12 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract
/** 校验列表筛选并统一状态大小写,防止无效状态被静默当成“全部”。 */ /** 校验列表筛选并统一状态大小写,防止无效状态被静默当成“全部”。 */
private TheoreticalPracticeDTO normalizePageQuery(TheoreticalPracticeDTO query) { private TheoreticalPracticeDTO normalizePageQuery(TheoreticalPracticeDTO query) {
TheoreticalPracticeDTO safe = query == null ? new TheoreticalPracticeDTO() : query; TheoreticalPracticeDTO safe = query == null ? new TheoreticalPracticeDTO() : query;
// 与等级选项接口返回的去空格值保持一致,并将纯空白条件视为未筛选。
if (StrUtil.isNotBlank(safe.getLev())) {
safe.setLev(safe.getLev().trim());
} else {
safe.setLev(null);
}
if (StrUtil.isNotBlank(safe.getStatus())) { if (StrUtil.isNotBlank(safe.getStatus())) {
String status = safe.getStatus().trim().toUpperCase(Locale.ROOT); String status = safe.getStatus().trim().toUpperCase(Locale.ROOT);
if (!TheoreticalPracticeConstants.ALLOWED_STATUSES.contains(status)) { if (!TheoreticalPracticeConstants.ALLOWED_STATUSES.contains(status)) {
......
...@@ -80,7 +80,16 @@ ...@@ -80,7 +80,16 @@
</when> </when>
</choose> </choose>
</where> </where>
order by c.training_year desc, c.occupation asc, sl.id asc, c.name asc, c.id asc <choose>
<when test="orderByCreateTime">
<!-- ID倒序用于稳定排列同一时刻创建的班级,也让没有创建时间的历史数据保持确定顺序。 -->
order by c.create_time desc, c.id desc
</when>
<otherwise>
<!-- 导航树依赖该顺序稳定组装年度、工种、等级和班级节点。 -->
order by c.training_year desc, c.occupation asc, sl.id asc, c.name asc, c.id asc
</otherwise>
</choose>
</select> </select>
<!-- <!--
......
...@@ -250,7 +250,17 @@ ...@@ -250,7 +250,17 @@
student.id_card as idCard, student.id_card as idCard,
student.sex, student.sex,
student.phone_number as phone, student.phone_number as phone,
student.factory, <!--
账号详情优先展示“实际用工单位”,其次展示“劳动关系单位”,最后兼容历史
factory 字段。考试新增弹窗必须遵循同一口径,否则新版账号只维护
company_name1/company_name2 时,这里的 factory 会返回 null,表格单位列为空。
NULLIF(TRIM(...), '') 同时跳过空字符串,避免空的新字段遮蔽有效的旧字段。
-->
coalesce(
nullif(trim(student.company_name2), ''),
nullif(trim(student.company_name1), ''),
nullif(trim(student.factory), '')
) as factory,
attendance.attendanceRate attendance.attendanceRate
from class_student member from class_student member
inner join user student on student.id = member.user_id inner join user student on student.id = member.user_id
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
cs.class_id = tp.class_id cs.class_id = tp.class_id
<where> <where>
<if test="query.lev != null and query.lev != ''"> <if test="query.lev != null and query.lev != ''">
and tp.lev = #{query.lev} and trim(tp.lev) = #{query.lev}
</if> </if>
<if test="query.status == 'PENDING'"> <if test="query.status == 'PENDING'">
and coalesce(tp.is_close, false) = false and coalesce(tp.is_close, false) = false
...@@ -61,6 +61,22 @@ ...@@ -61,6 +61,22 @@
tp.id, tp.lev, tp.class_id, c.name, tp.start_time, tp.end_time, tp.creator, tp.creator_id, tp.create_time, tp.is_close tp.id, tp.lev, tp.class_id, c.name, tp.start_time, tp.end_time, tp.creator, tp.creator_id, tp.create_time, tp.is_close
order by tp.create_time desc order by tp.create_time desc
</select> </select>
<!--
列表筛选必须覆盖理论练习表中真实存在的全部等级。不能从班级导航树的固定层级
或单个工种分支截取,否则历史数据缺少工种、同一年度存在多个工种时会漏选项。
trim同时合并旧数据中仅首尾空格不同的重复等级,并与分页筛选条件保持一致。
-->
<select id="selectLevelOptions"
resultType="com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO">
select trim(tp.lev) as value,
trim(tp.lev) as label
from theoretical_practice tp
where tp.lev is not null
and trim(tp.lev) != ''
group by trim(tp.lev)
order by trim(tp.lev) asc
</select>
<select id="detail" resultType="com.platform.business.model.vo.TheoreticalPracticeVO"> <select id="detail" resultType="com.platform.business.model.vo.TheoreticalPracticeVO">
select select
id, id,
......
...@@ -16,6 +16,27 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql ...@@ -16,6 +16,27 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql
## 2. 一级页面分页 ## 2. 一级页面分页
### 2.1 等级筛选项
`GET /theoretical/practice/levels`
返回理论练习表中实际存在的全部非空等级,每项包含相同语义的 `value` 和 `label`。
页面应直接使用该接口渲染等级下拉框,不再从“工种 → 学年 → 等级 → 班级”导航树的
局部分支提取等级。这样历史班级缺少工种、跨学年或跨工种时都不会遗漏筛选项。
```json
{
"code": 200,
"data": [
{"value": "技能竞赛", "label": "技能竞赛"},
{"value": "污水四级", "label": "污水四级"},
{"value": "污泥五级", "label": "污泥五级"}
]
}
```
### 2.2 分页查询
`POST /theoretical/practice/page` `POST /theoretical/practice/page`
```json ```json
...@@ -31,8 +52,9 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql ...@@ -31,8 +52,9 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql
- `status`:`PENDING`、`ONGOING`、`ENDED`,忽略大小写。 - `status`:`PENDING`、`ONGOING`、`ENDED`,忽略大小写。
- 时间采用完整包含口径:练习开始时间不早于起始日,结束时间不晚于结束日当天。 - 时间采用完整包含口径:练习开始时间不早于起始日,结束时间不晚于结束日当天。
- 返回仍为项目统一 `TableDataInfo`。原有中文 `status` 保留,并新增 `statusCode`。 - 返回仍为项目统一 `TableDataInfo`,并同时提供中文 `status` 和稳定的 `statusCode`。
- `ENDED` 同时包含自然到期和手动关闭;中文状态仍区分“已结束”和“已手动关闭”。 - 状态统一为 `PENDING` / 未开始、`ONGOING` / 进行中、`ENDED` / 已结束。
- `ENDED` 同时包含自然到期和手动关闭,列表中均展示“已结束”。
## 3. 一级页面全局统计 ## 3. 一级页面全局统计
......
package com.platform.business.controller; package com.platform.business.controller;
import com.platform.business.model.entity.UserEntity; import com.platform.business.model.entity.UserEntity;
import com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO;
import com.platform.business.service.AuthenticatedUserService; import com.platform.business.service.AuthenticatedUserService;
import com.platform.business.service.TheoreticalPracticeService; import com.platform.business.service.TheoreticalPracticeService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
...@@ -13,6 +14,8 @@ import org.springframework.mock.web.MockHttpServletRequest; ...@@ -13,6 +14,8 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
...@@ -58,6 +61,24 @@ class TheoreticalPracticeControllerTest { ...@@ -58,6 +61,24 @@ class TheoreticalPracticeControllerTest {
verify(theoreticalPracticeService).exportStudentStatistics("p1", "s1", response); verify(theoreticalPracticeService).exportStudentStatistics("p1", "s1", response);
} }
@Test
void levelOptionsShouldRequireAdminAndForwardCompleteOptions() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserEntity administrator = new UserEntity();
TheoreticalPracticeLevelOptionVO option = new TheoreticalPracticeLevelOptionVO();
option.setValue("污泥五级");
option.setLabel("污泥五级");
when(authenticatedUserService.current(request)).thenReturn(administrator);
when(theoreticalPracticeService.levelOptions())
.thenReturn(Collections.singletonList(option));
controller.levels(request);
// 等级选项包含管理端业务数据,与练习列表使用相同的管理员权限边界。
verify(authenticatedUserService).requireAdmin(administrator);
verify(theoreticalPracticeService).levelOptions();
}
@Test @Test
void statisticsEndpointShouldStopWhenCurrentUserIsNotAdmin() { void statisticsEndpointShouldStopWhenCurrentUserIsNotAdmin() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
......
package com.platform.business.mapper;
import com.platform.business.model.dto.ClassAdminQueryDTO;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** 管理员班级列表与导航树排序规则的Mapper XML回归测试。 */
class ClassMapperXmlTest {
@Test
void adminClassQueryShouldUseTheOrderingRequestedByItsCaller() throws Exception {
String resource = "com/platform/business/mapper/ClassMapper.xml";
Configuration configuration = new Configuration();
try (InputStream input = Resources.getResourceAsStream(resource)) {
new XMLMapperBuilder(input, configuration, resource,
configuration.getSqlFragments()).parse();
}
// 模拟卡片分页调用,验证排序发生在数据库分页之前,并以ID作为稳定的第二排序键。
String cardSql = compactSql(adminClassSql(configuration, true));
assertTrue(cardSql.contains("order by c.create_time desc, c.id desc"));
assertFalse(cardSql.contains("order by c.training_year desc"));
// 导航树与卡片列表共用过滤SQL,但应继续保持原有的分组顺序。
String treeSql = compactSql(adminClassSql(configuration, false));
assertTrue(treeSql.contains(
"order by c.training_year desc, c.occupation asc, sl.id asc, c.name asc, c.id asc"));
assertFalse(treeSql.contains("order by c.create_time desc"));
}
private static String adminClassSql(Configuration configuration,
boolean orderByCreateTime) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("query", new ClassAdminQueryDTO());
parameters.put("today", java.sql.Date.valueOf("2026-09-02"));
parameters.put("orderByCreateTime", orderByCreateTime);
return configuration.getMappedStatement(
"com.platform.business.mapper.ClassMapper.selectAdminClasses")
.getBoundSql(parameters).getSql();
}
private static String compactSql(String sql) {
return sql.replaceAll("\\s+", " ").trim();
}
}
...@@ -6,6 +6,7 @@ import org.apache.ibatis.session.Configuration; ...@@ -6,6 +6,7 @@ import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
...@@ -28,5 +29,21 @@ class ExamMapperXmlTest { ...@@ -28,5 +29,21 @@ class ExamMapperXmlTest {
"com.platform.business.mapper.ExamMapper.selectAdminExamConflicts")); "com.platform.business.mapper.ExamMapper.selectAdminExamConflicts"));
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.ExamMapper.updateAdminExam")); "com.platform.business.mapper.ExamMapper.updateAdminExam"));
/*
* 学员详情使用新版 company_name1/company_name2 保存单位,旧数据则仍可能只保存
* factory。这里直接检查 MyBatis 最终生成的 SQL,防止后续改动又退回只查询旧字段,
* 导致新增考试弹窗的“单位”列再次为空。
*/
String studentOptionsSql = configuration.getMappedStatement(
"com.platform.business.mapper.ExamMapper.selectAdminExamStudentOptions")
.getBoundSql(Collections.singletonMap("classId", 1))
.getSql()
.replaceAll("\\s+", " ")
.toLowerCase();
assertTrue(studentOptionsSql.contains(
"coalesce( nullif(trim(student.company_name2), ''), "
+ "nullif(trim(student.company_name1), ''), "
+ "nullif(trim(student.factory), '') ) as factory"));
} }
} }
...@@ -19,6 +19,8 @@ class TheoreticalPracticeMapperXmlTest { ...@@ -19,6 +19,8 @@ class TheoreticalPracticeMapperXmlTest {
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.TheoreticalPracticeMapper.summary")); "com.platform.business.mapper.TheoreticalPracticeMapper.summary"));
assertTrue(configuration.hasStatement(
"com.platform.business.mapper.TheoreticalPracticeMapper.selectLevelOptions"));
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.TheoreticalPracticeMapper.statisticsOverview")); "com.platform.business.mapper.TheoreticalPracticeMapper.statisticsOverview"));
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
......
...@@ -20,6 +20,7 @@ import org.mockito.InjectMocks; ...@@ -20,6 +20,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
...@@ -107,6 +108,64 @@ class TheoreticalPaperAdminServiceImplTest { ...@@ -107,6 +108,64 @@ class TheoreticalPaperAdminServiceImplTest {
assertEquals("teacher-1", paperCaptor.getValue().getCreatorId()); assertEquals("teacher-1", paperCaptor.getValue().getCreatorId());
} }
@Test
void manualPublishShouldStripLegacyRenderedOptionsBeforeSavingQuestion() {
String stem = "污水处理过程中,下列说法正确的是( )。";
TheoreticalPaperDetailEntity question = new TheoreticalPaperDetailEntity();
question.setType("单选题");
question.setOptionA("应当严格执行工艺操作规程,完整记录关键运行参数并及时处理异常情况");
question.setOptionB("设备出现异常后仍可不经任何检查,继续长时间运行直至完成全部生产任务");
question.setOptionC("为了减少日常工作量,可以省略全部巡检、运行记录以及班组交接记录");
question.setOptionD("任何运行工况和检修状态下,都可以绕过安全联锁直接强制启动设备");
question.setAnswer("A");
question.setScore(2D);
// 模拟旧题库分页接口:problem 已经包含一份用于页面展示的 A-D 选项,
// 同一个请求中又带有独立 optionA-optionD 字段;拼接结果超过明细表128字符限制。
question.setProblem(stem
+ "\nA." + question.getOptionA()
+ "\nB." + question.getOptionB()
+ "\nC." + question.getOptionC()
+ "\nD." + question.getOptionD() + "\n");
assertTrue(question.getProblem().length() > 128);
TheoreticalPaperManualSaveDTO request = new TheoreticalPaperManualSaveDTO();
request.setLev("污水四级");
request.setName("旧版展示字段兼容卷");
request.setSequence("顺序");
request.setStatus("PUBLISHED");
request.setQuestions(Collections.singletonList(question));
when(paperMapper.countAdminDuplicateName(request.getName(), null)).thenReturn(0);
when(paperMapper.insert(any(TheoreticalPaperEntity.class))).thenAnswer(invocation -> {
TheoreticalPaperEntity paper = invocation.getArgument(0);
paper.setId("paper-legacy-rendered");
return 1;
});
when(paperDetailService.saveBatch(any())).thenReturn(true);
TheoreticalPaperVO saved = new TheoreticalPaperVO();
saved.setId("paper-legacy-rendered");
saved.setStatus("PUBLISHED");
when(paperMapper.selectAdminDetail("paper-legacy-rendered")).thenReturn(saved);
when(paperMapper.selectAdminQuestions("paper-legacy-rendered"))
.thenReturn(Collections.singletonList(question));
service.createManual(request, "管理员甲");
// 捕获真正交给 MyBatis-Plus 批量保存的对象,确保落库的是纯题干而不是页面展示串。
@SuppressWarnings("unchecked")
ArgumentCaptor<Collection<TheoreticalPaperDetailEntity>> questionsCaptor =
ArgumentCaptor.forClass(Collection.class);
verify(paperDetailService).saveBatch(questionsCaptor.capture());
TheoreticalPaperDetailEntity persisted = questionsCaptor.getValue().iterator().next();
assertEquals(stem, persisted.getProblem());
assertEquals(question.getOptionA(), persisted.getOptionA());
assertTrue(persisted.getProblem().length() <= 128);
ArgumentCaptor<TheoreticalPaperEntity> paperCaptor =
ArgumentCaptor.forClass(TheoreticalPaperEntity.class);
verify(paperMapper).insert(paperCaptor.capture());
assertEquals("PUBLISHED", paperCaptor.getValue().getStatus());
}
@Test @Test
void automaticCreateShouldRejectWhenQuestionBankIsInsufficient() { void automaticCreateShouldRejectWhenQuestionBankIsInsufficient() {
TheoreticalPaperAutoSaveDTO request = new TheoreticalPaperAutoSaveDTO(); TheoreticalPaperAutoSaveDTO request = new TheoreticalPaperAutoSaveDTO();
......
...@@ -5,16 +5,19 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO; ...@@ -5,16 +5,19 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO; import com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO;
import com.platform.business.model.entity.TheoreticalPracticeEntity; import com.platform.business.model.entity.TheoreticalPracticeEntity;
import com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO;
import com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO;
import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO; import com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO;
import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO; import com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO;
import com.platform.business.model.vo.TheoreticalPracticeSummaryVO; import com.platform.business.model.vo.TheoreticalPracticeSummaryVO;
import com.platform.business.model.vo.TheoreticalPracticeVO;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.ArgumentCaptor;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
...@@ -66,6 +69,64 @@ class TheoreticalPracticeServiceImplTest { ...@@ -66,6 +69,64 @@ class TheoreticalPracticeServiceImplTest {
assertThrows(BusinessException.class, () -> service.page(query)); assertThrows(BusinessException.class, () -> service.page(query));
} }
@Test
void levelOptionsShouldUseDedicatedFullPracticeLevelQuery() {
TheoreticalPracticeLevelOptionVO wastewater = levelOption("污水一级");
TheoreticalPracticeLevelOptionVO sludge = levelOption("污泥五级");
TheoreticalPracticeLevelOptionVO competition = levelOption("技能竞赛");
when(mapper.selectLevelOptions())
.thenReturn(Arrays.asList(competition, wastewater, sludge));
List<TheoreticalPracticeLevelOptionVO> options = service.levelOptions();
assertEquals(3, options.size());
assertEquals("技能竞赛", options.get(0).getValue());
assertEquals("污水一级", options.get(1).getLabel());
assertEquals("污泥五级", options.get(2).getValue());
verify(mapper).selectLevelOptions();
}
@Test
void pageShouldTrimLevelFilterReturnedByOptionsEndpoint() {
when(mapper.page(any(TheoreticalPracticeDTO.class), any(Date.class)))
.thenReturn(Collections.emptyList());
TheoreticalPracticeDTO query = new TheoreticalPracticeDTO();
query.setLev(" 污泥五级 ");
service.page(query);
ArgumentCaptor<TheoreticalPracticeDTO> captor =
ArgumentCaptor.forClass(TheoreticalPracticeDTO.class);
verify(mapper).page(captor.capture(), any(Date.class));
assertEquals("污泥五级", captor.getValue().getLev());
}
@Test
void pageShouldReturnProductDefinedThreeStateLabels() {
// 使用固定的远期和历史时间构造三种自然状态,避免测试依赖执行当天的日期。
Date past = new Date(946684800000L);
Date future = new Date(4102444800000L);
TheoreticalPracticeVO pending = practice(future, future, false);
TheoreticalPracticeVO ongoing = practice(past, future, false);
TheoreticalPracticeVO ended = practice(past, past, false);
TheoreticalPracticeVO manuallyClosed = practice(past, future, true);
when(mapper.page(any(TheoreticalPracticeDTO.class), any(Date.class)))
.thenReturn(Arrays.asList(pending, ongoing, ended, manuallyClosed));
List<TheoreticalPracticeVO> rows = service.page(new TheoreticalPracticeDTO());
assertEquals("未开始", rows.get(0).getStatus());
assertEquals("PENDING", rows.get(0).getStatusCode());
assertEquals("进行中", rows.get(1).getStatus());
assertEquals("ONGOING", rows.get(1).getStatusCode());
assertEquals("已结束", rows.get(2).getStatus());
assertEquals("ENDED", rows.get(2).getStatusCode());
// 手动关闭属于结束态,产品列表不再额外展示第四种状态。
assertEquals("已结束", rows.get(3).getStatus());
assertEquals("ENDED", rows.get(3).getStatusCode());
}
@Test @Test
void overviewShouldUseAllAssignedStudentsAndRoundRates() { void overviewShouldUseAllAssignedStudentsAndRoundRates() {
TheoreticalPracticeStatisticsOverviewVO raw = new TheoreticalPracticeStatisticsOverviewVO(); TheoreticalPracticeStatisticsOverviewVO raw = new TheoreticalPracticeStatisticsOverviewVO();
...@@ -167,4 +228,21 @@ class TheoreticalPracticeServiceImplTest { ...@@ -167,4 +228,21 @@ class TheoreticalPracticeServiceImplTest {
row.setStudyDurationSeconds(0L); row.setStudyDurationSeconds(0L);
return row; return row;
} }
/** 创建用于列表状态断言的最小理论练习对象。 */
private TheoreticalPracticeVO practice(Date startTime, Date endTime, boolean isClose) {
TheoreticalPracticeVO practice = new TheoreticalPracticeVO();
practice.setStartTime(startTime);
practice.setEndTime(endTime);
practice.setIsClose(isClose);
return practice;
}
/** 创建列表筛选接口使用的最小等级选项。 */
private TheoreticalPracticeLevelOptionVO levelOption(String level) {
TheoreticalPracticeLevelOptionVO option = new TheoreticalPracticeLevelOptionVO();
option.setValue(level);
option.setLabel(level);
return option;
}
} }
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