【修改】监控管理,【新增】学生端试卷接口

This commit is contained in:
YOHO\20373
2025-05-05 21:19:14 +08:00
47 changed files with 722 additions and 45 deletions

View File

@@ -27,7 +27,8 @@ import static pc.exam.pp.framework.apilog.core.enums.OperateTypeEnum.*;
import pc.exam.pp.module.exam.controller.admin.monitor.vo.*; import pc.exam.pp.module.exam.controller.admin.monitor.vo.*;
import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO; import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
import pc.exam.pp.module.exam.service.monitor.MonitorService; import pc.exam.pp.module.exam.service.monitor.MonitorService;
import static pc.exam.pp.module.infra.enums.ErrorCodeConstants.DEMO03_MONITOR_SESSION_EXISTS;
import static pc.exam.pp.module.infra.enums.ErrorCodeConstants.DEMO03_MONITOR_TIME_EXISTS;
@Tag(name = "管理后台 - 监控管理") @Tag(name = "管理后台 - 监控管理")
@RestController @RestController
@@ -92,13 +93,18 @@ public void exportMonitorExcel(@Valid MonitorPageReqVO pageReqVO, HttpServletRes
{ {
return success("进入考试成功"); return success("进入考试成功");
} }
return error(100_200_300,"不在考试时间范围内!"); return error(DEMO03_MONITOR_TIME_EXISTS);
} }
@PostMapping("/stuMonitorQu") @PostMapping("/stuMonitorQu")
@Operation(summary = "学生端考试过程传试题") @Operation(summary = "学生端考试过程传试题")
public void updateStuMonitor(@Valid @RequestBody StuMonitorQuVo stuMonitorQuVo) { public CommonResult<String> updateStuMonitor(@Valid @RequestBody StuMonitorQuVo stuMonitorQuVo) {
monitorService.updateStuMonitor(stuMonitorQuVo); Boolean stuMonitor= monitorService.updateStuMonitor(stuMonitorQuVo);
if (!stuMonitor)
{
return error(DEMO03_MONITOR_SESSION_EXISTS);
}
return success("传值成功");
} }
@PostMapping("/endMonitor") @PostMapping("/endMonitor")
@Operation(summary = "学生端结束考试返回值") @Operation(summary = "学生端结束考试返回值")
@@ -106,4 +112,19 @@ public void exportMonitorExcel(@Valid MonitorPageReqVO pageReqVO, HttpServletRes
monitorService.endStuMonitor(stuMonitorPaperEndVo); monitorService.endStuMonitor(stuMonitorPaperEndVo);
} }
@GetMapping("/getPaperTaskList")
@Operation(summary = "根据种类获得试卷任务")
@Parameter(name = "id", description = "试卷种类", required = true, example = "1024")
public CommonResult getPaperTaskList(@RequestParam("id") String id) {
return success(monitorService.getPaperTaskList(id));
}
@PostMapping("/updateMonitorStatus")
@Operation(summary = "改变考生状态")
public CommonResult updateMonitorStatus(@Valid @RequestBody StuMonitorStatusVo stuMonitorStatusVo) {
return success(monitorService.updateMonitorStatus(stuMonitorStatusVo));
}
} }

View File

@@ -1,6 +1,7 @@
package pc.exam.pp.module.exam.controller.admin.monitor.vo; package pc.exam.pp.module.exam.controller.admin.monitor.vo;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.*; import lombok.*;
import java.util.*; import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@@ -15,6 +16,7 @@ import static pc.exam.pp.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class MonitorPageReqVO extends PageParam { public class MonitorPageReqVO extends PageParam {
private String [] monitorId;
@Schema(description = "用户账号", example = "芋艿") @Schema(description = "用户账号", example = "芋艿")
private String username; private String username;
@@ -37,6 +39,8 @@ private String paperNum;
@Schema(description = "场次", example = "赵六") @Schema(description = "场次", example = "赵六")
private String taskName; private String taskName;
private String taskType;
@Schema(description = "机器ip") @Schema(description = "机器ip")
private String ip; private String ip;

View File

@@ -39,10 +39,14 @@ private String score;
@ExcelProperty("试卷编号") @ExcelProperty("试卷编号")
private String paperNum; private String paperNum;
@Schema(description = "场次", example = "赵六") @Schema(description = "任务名称")
@ExcelProperty("场次") @ExcelProperty("任务名称")
private String taskName; private String taskName;
@Schema(description = "任务类别")
@ExcelProperty("任务类别")
private String taskType;
@Schema(description = "机器ip") @Schema(description = "机器ip")
@ExcelProperty("机器ip") @ExcelProperty("机器ip")
private String ip; private String ip;

View File

@@ -0,0 +1,12 @@
package pc.exam.pp.module.exam.controller.admin.monitor.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 监控管理 改变学生考试状态 Request VO")
@Data
public class StuMonitorStatusVo {
private List<String> monitorIds;
private String status;
}

View File

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.common.util.object.BeanUtils; import pc.exam.pp.framework.common.util.object.BeanUtils;
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
import pc.exam.pp.module.exam.controller.admin.paper.dto.PaperQueryRequest; import pc.exam.pp.module.exam.controller.admin.paper.dto.PaperQueryRequest;
import pc.exam.pp.module.exam.controller.admin.paper.dto.StatusDto; import pc.exam.pp.module.exam.controller.admin.paper.dto.StatusDto;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo; import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
@@ -19,6 +20,7 @@ import pc.exam.pp.module.exam.service.paper.IEducationPaperService;
import java.util.List; import java.util.List;
import static pc.exam.pp.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; import static pc.exam.pp.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/** /**
* 试卷Controller * 试卷Controller
@@ -152,8 +154,6 @@ public class EducationPaperController
@PostMapping(value = "/getPaperByTaskIdByType") @PostMapping(value = "/getPaperByTaskIdByType")
public CommonResult getPaperByTaskIdByType(@RequestBody PaperQueryRequest requestData) public CommonResult getPaperByTaskIdByType(@RequestBody PaperQueryRequest requestData)
{ {
return CommonResult.success(educationPaperService.getPaperByTaskIdByType(requestData.getTaskId(), requestData.getRows())); return CommonResult.success(educationPaperService.getPaperByTaskIdByType(requestData.getTaskId(), requestData.getRows()));
} }
@@ -165,4 +165,14 @@ public class EducationPaperController
); );
} }
@GetMapping("/stulist")
public CommonResult<PageResult<EducationPaperStuDto>> stulist(PaperPageVo paperPageVo)
{
PageResult<EducationPaperStuDto> pageResult = educationPaperService.selectStuEducationPaperList(paperPageVo);
return CommonResult.success(pageResult);
}
} }

View File

@@ -0,0 +1,39 @@
package pc.exam.pp.module.exam.controller.admin.paper.dto;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperParam;
@Data
public class EducationPaperStuDto {
private static final long serialVersionUID = 1L;
/** 主键ID */
@TableId
private String paperId;
/** 试卷任务ID */
// @Excel(name = "试卷任务ID")
private String taskId;
private String num;
/** 使用次数 */
// @Excel(name = "使用次数")
private String counts;
/** 抽卷方式(0固定1AB2随机) */
//@Excel(name = "抽卷方式(0固定1AB2随机)")
private String rollUp;
/** 0A1B */
//Excel(name = "0A1B")
private String isAb;
EducationPaperParam educationPaperParam;
}

View File

@@ -5,6 +5,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import pc.exam.pp.framework.common.pojo.PageParam; import pc.exam.pp.framework.common.pojo.PageParam;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperParam;
@Schema(description = "试卷vo") @Schema(description = "试卷vo")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)

View File

@@ -48,6 +48,5 @@ public class EducationPaper extends TenantBaseDO
// @Excel(name = "0启用1不启") // @Excel(name = "0启用1不启")
private String status; private String status;
} }

View File

@@ -27,6 +27,12 @@ public class EducationPaperParam
/** 试卷任务ID */ /** 试卷任务ID */
// @Excel(name = "试卷任务ID") // @Excel(name = "试卷任务ID")
private String taskId; private String taskId;
//是否显示试卷编号
private String isNumber;
//是否显示试卷内容
private String isContent;
//是否显示答案id
private String isAnswerId;
/** 是否使用监考密码验证0是1否 */ /** 是否使用监考密码验证0是1否 */
// @Excel(name = "是否使用监考密码验证", readConverterExp = "0=是1否") // @Excel(name = "是否使用监考密码验证", readConverterExp = "0=是1否")

View File

@@ -1,5 +1,6 @@
package pc.exam.pp.module.exam.dal.dataobject; package pc.exam.pp.module.exam.dal.dataobject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@@ -24,6 +25,7 @@ public class EducationPaperSession
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 主键ID */ /** 主键ID */
@TableId
private String sessionId; private String sessionId;
/** 试卷任务ID */ /** 试卷任务ID */

View File

@@ -1,6 +1,8 @@
package pc.exam.pp.module.exam.dal.dataobject; package pc.exam.pp.module.exam.dal.dataobject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@@ -39,6 +41,8 @@ public class EducationPaperTask extends TenantBaseDO
//@Excel(name = "试卷任务模式") //@Excel(name = "试卷任务模式")
private String taskType; private String taskType;
private String isOne;
/** 是否为模板 */ /** 是否为模板 */
//@Excel(name = "是否为模板") //@Excel(name = "是否为模板")
private String isTemplate; private String isTemplate;
@@ -47,8 +51,8 @@ public class EducationPaperTask extends TenantBaseDO
//@Excel(name = "是否启用", readConverterExp = "0=:启用1:停用") //@Excel(name = "是否启用", readConverterExp = "0=:启用1:停用")
private String status; private String status;
@TableField(exist = false)
private String count;
} }

View File

@@ -27,6 +27,8 @@ public class MonitorDO extends BaseDO {
*/ */
@TableId(type = IdType.INPUT) @TableId(type = IdType.INPUT)
private String monitorId; private String monitorId;
private String stuId;
/** /**
* 用户账号 * 用户账号
*/ */
@@ -51,10 +53,11 @@ private String score;
* 试卷编号 * 试卷编号
*/ */
private String paperNum; private String paperNum;
/**
* 场次 private String taskId;
*/
private String taskName; private String taskName;
private String taskType;
/** /**
* 机器ip * 机器ip
*/ */

View File

@@ -0,0 +1,38 @@
package pc.exam.pp.module.exam.dal.dataobject.student;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import pc.exam.pp.framework.tenant.core.db.TenantBaseDO;
/**
* 学生-试卷-文件表 DO
*
* @author rwb
*/
@TableName("exam_stu_paper_fileurl")
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StuPaperFileDO extends TenantBaseDO {
/**
* Id
*/
@TableId
private Long id;
/**
* 学生号
*/
private Long stuId;
/**
* 试卷ID
*/
private String paperId;
/**
* 学生文件URL
*/
private String url;
}

View File

@@ -8,6 +8,9 @@ import org.apache.ibatis.annotations.Mapper;
import pc.exam.pp.module.exam.controller.admin.monitor.vo.MonitorPageReqVO; import pc.exam.pp.module.exam.controller.admin.monitor.vo.MonitorPageReqVO;
import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO; import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
import java.util.Arrays;
import java.util.Optional;
/** /**
* 监控管理 Mapper * 监控管理 Mapper
* *
@@ -18,10 +21,12 @@ import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
default PageResult<MonitorDO> selectPage(MonitorPageReqVO reqVO) { default PageResult<MonitorDO> selectPage(MonitorPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MonitorDO>() return selectPage(reqVO, new LambdaQueryWrapperX<MonitorDO>()
.inIfPresent(MonitorDO::getMonitorId, Optional.ofNullable(reqVO.getMonitorId()).map(Arrays::asList).orElse(null))
.likeIfPresent(MonitorDO::getUsername, reqVO.getUsername()) .likeIfPresent(MonitorDO::getUsername, reqVO.getUsername())
.likeIfPresent(MonitorDO::getNickname, reqVO.getNickname()) .likeIfPresent(MonitorDO::getNickname, reqVO.getNickname())
.likeIfPresent(MonitorDO::getClassName, reqVO.getClassName()) .likeIfPresent(MonitorDO::getClassName, reqVO.getClassName())
.eqIfPresent(MonitorDO::getExamStatus, reqVO.getExamStatus()) .eqIfPresent(MonitorDO::getExamStatus, reqVO.getExamStatus())
.eqIfPresent(MonitorDO::getTaskType, reqVO.getTaskType())
.eqIfPresent(MonitorDO::getScore, reqVO.getScore()) .eqIfPresent(MonitorDO::getScore, reqVO.getScore())
.eqIfPresent(MonitorDO::getPaperNum, reqVO.getPaperNum()) .eqIfPresent(MonitorDO::getPaperNum, reqVO.getPaperNum())
.likeIfPresent(MonitorDO::getTaskName, reqVO.getTaskName()) .likeIfPresent(MonitorDO::getTaskName, reqVO.getTaskName())

View File

@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX; import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo; import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo; import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper; import pc.exam.pp.module.exam.dal.dataobject.EducationPaper;
@@ -121,5 +122,12 @@ public interface EducationPaperMapper extends BaseMapperX<EducationPaper>
int selectCountPaperList(); int selectCountPaperList();
default PageResult<EducationPaper> selectStuEducationPaperList(PaperPageVo paperPageVo) {
return selectPage(paperPageVo, new LambdaQueryWrapperX<EducationPaper>()
.likeIfPresent(EducationPaper::getTaskId, paperPageVo.getTaskId())
.isNotNull(EducationPaper::getRollUp) // 改为数据库字段不为 null
.eq(EducationPaper::getStatus, 0)
);
}
} }

View File

@@ -107,4 +107,5 @@ public interface EducationPaperPersonMapper
List<PersonRepDto> selectEducationPaperPersonBySessionIdNotIn(SessionStuPageReqVO sessionStuPageReqVO); List<PersonRepDto> selectEducationPaperPersonBySessionIdNotIn(SessionStuPageReqVO sessionStuPageReqVO);
List<String> selectStuIdByTaskId(String taskId);
} }

View File

@@ -109,4 +109,5 @@ public interface EducationPaperTaskMapper extends BaseMapperX<EducationPaperTask
String selectStuClassNameByClassId(Long classId); String selectStuClassNameByClassId(Long classId);
List<EducationPaperTask> selectEducationPaperTaskByTaskType(String id);
} }

View File

@@ -0,0 +1,18 @@
package pc.exam.pp.module.exam.dal.mysql.student;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
/**
* 学生-试卷-文件 Mapper
*
* @author rwb
*/
@Mapper
public interface StuPaperFileMapper extends BaseMapperX<StuPaperFileDO> {
StuPaperFileDO findByStuIdAndPaperId(@Param("stuId") Long stuId, @Param("paperId") String paperId);
}

View File

@@ -3,8 +3,11 @@ package pc.exam.pp.module.exam.service.monitor;
import jakarta.validation.*; import jakarta.validation.*;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.module.exam.controller.admin.monitor.vo.*; import pc.exam.pp.module.exam.controller.admin.monitor.vo.*;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperTask;
import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO; import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
import java.util.List;
/** /**
* 监控管理 Service 接口 * 监控管理 Service 接口
* *
@@ -52,8 +55,11 @@ import pc.exam.pp.module.exam.dal.dataobject.monitor.MonitorDO;
Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo); Boolean getStuMonitor(StuMonitorPaperVo stuMonitorPaperVo);
void updateStuMonitor(StuMonitorQuVo stuMonitorQuVo); Boolean updateStuMonitor(StuMonitorQuVo stuMonitorQuVo);
void endStuMonitor(StuMonitorPaperEndVo stuMonitorPaperEndVo); void endStuMonitor(StuMonitorPaperEndVo stuMonitorPaperEndVo);
List<EducationPaperTask> getPaperTaskList(String id);
Boolean updateMonitorStatus(StuMonitorStatusVo stuMonitorStatusVo);
} }

View File

@@ -108,6 +108,18 @@ public class MonitorServiceImpl implements MonitorService {
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
if (StringUtils.isNotBlank(stuMonitorPaperVo.getPaperId())){ if (StringUtils.isNotBlank(stuMonitorPaperVo.getPaperId())){
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperVo.getPaperId()); EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(stuMonitorPaperVo.getPaperId());
String counts = educationPaper.getCounts();
int count = 0;
try {
count = Integer.parseInt(counts);
} catch (NumberFormatException | NullPointerException e) {
count = 0; // 默认从 0 开始
}
count += 1;
educationPaper.setCounts(String.valueOf(count));
educationPaperMapper.updateById(educationPaper);
info.setPaperNum(educationPaper.getNum()); info.setPaperNum(educationPaper.getNum());
} }
@@ -153,6 +165,9 @@ public class MonitorServiceImpl implements MonitorService {
long remainingSeconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), long remainingSeconds = ChronoUnit.SECONDS.between(LocalDateTime.now(),
DateUtil.toLocalDateTime(endTime)); DateUtil.toLocalDateTime(endTime));
info.setRemainingTime(remainingSeconds > 0 ? remainingSeconds : 0); info.setRemainingTime(remainingSeconds > 0 ? remainingSeconds : 0);
//todo 考虑加点时间,或判分后删除
stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info), remainingSeconds, TimeUnit.SECONDS); stringRedisTemplate.opsForValue().set("userCache:"+stuMonitorPaperVo.getTaskId()+":"+stuMonitorPaperVo.getStuId(), JsonUtils.toJsonString(info), remainingSeconds, TimeUnit.SECONDS);
monitorMapper.updateById(info); monitorMapper.updateById(info);
return true; return true;
@@ -164,10 +179,13 @@ public class MonitorServiceImpl implements MonitorService {
} }
@Override @Override
public void updateStuMonitor(StuMonitorQuVo stuMonitorQuVo) { public Boolean updateStuMonitor(StuMonitorQuVo stuMonitorQuVo) {
String key = "userCache:"+stuMonitorQuVo.getTaskId()+":" + stuMonitorQuVo.getStuId(); String key = "userCache:"+stuMonitorQuVo.getTaskId()+":" + stuMonitorQuVo.getStuId();
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class); MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
if (info != null) { if (info != null) {
if (!("1".equals(info.getExamStatus()))){
return false;
}
AtomicInteger totalScore = new AtomicInteger(); // 用于累加总分 AtomicInteger totalScore = new AtomicInteger(); // 用于累加总分
// 记录答题结果 // 记录答题结果
List<StuMonitorQuVo.EducationPaperSchemeMap> paperSchemeMaps = stuMonitorQuVo.getPaperSchemeMaps(); List<StuMonitorQuVo.EducationPaperSchemeMap> paperSchemeMaps = stuMonitorQuVo.getPaperSchemeMaps();
@@ -193,6 +211,7 @@ public class MonitorServiceImpl implements MonitorService {
redisTemplate.opsForValue().set(key, info); redisTemplate.opsForValue().set(key, info);
// monitorMapper.updateById(info); // monitorMapper.updateById(info);
} }
return true;
} }
@@ -216,11 +235,57 @@ public class MonitorServiceImpl implements MonitorService {
info.setExamStatus("0"); info.setExamStatus("0");
}else { }else {
info.setExamStatus("2"); info.setExamStatus("2");
redisTemplate.delete(key);
} }
redisTemplate.delete(key);
monitorMapper.updateById(info); monitorMapper.updateById(info);
} }
@Override
public List<EducationPaperTask> getPaperTaskList(String id) {
return educationPaperTaskMapper.selectEducationPaperTaskByTaskType(id);
}
@Override
public Boolean updateMonitorStatus(StuMonitorStatusVo stuMonitorStatusVo) {
String status = stuMonitorStatusVo.getStatus();
List<String> monitorIds = stuMonitorStatusVo.getMonitorIds();
if ("1".equals(status)||"0".equals(status)){
//新增或更新
for (String monitorId : monitorIds) {
MonitorDO monitorDO = monitorMapper.selectById(monitorId);
String taskId = monitorDO.getTaskId();
String stuId = monitorDO.getStuId();
String key = "userCache:" + taskId+":" +stuId;
monitorDO.setExamStatus(status);
monitorMapper.updateById(monitorDO);
MonitorDO info = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(key),MonitorDO.class);
info.setExamStatus(status);
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
}
}
if ("2".equals(status)){
//删除
for (String monitorId : monitorIds) {
MonitorDO monitorDO = monitorMapper.selectById(monitorId);
String taskId = monitorDO.getTaskId();
String stuId = monitorDO.getStuId();
String key = "userCache:" + taskId+":" +stuId;
monitorDO.setExamStatus(status);
monitorMapper.updateById(monitorDO);
redisTemplate.delete(key);
}
}
return true;
}
} }

View File

@@ -196,7 +196,7 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
} else if (existing == null) { } else if (existing == null) {
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId);
String name= educationPaperTaskMapper.selectEducationPaperTaskNameByid(taskId); String name= educationPaperTaskMapper.selectEducationPaperTaskNameByid(taskId);
@@ -206,6 +206,8 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
String uuid = IdUtils.simpleUUID(); String uuid = IdUtils.simpleUUID();
MonitorDO info = new MonitorDO(); MonitorDO info = new MonitorDO();
info.setMonitorId(uuid); info.setMonitorId(uuid);
info.setTaskId(taskId);
info.setStuId(studentId);
info.setUsername(personRepDto.getUsername()); info.setUsername(personRepDto.getUsername());
info.setNickname(personRepDto.getNickname()); info.setNickname(personRepDto.getNickname());
//设置学生班级 //设置学生班级
@@ -217,6 +219,7 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
info.setScore("0"); info.setScore("0");
info.setPaperNum(""); info.setPaperNum("");
info.setTaskName(name); info.setTaskName(name);
info.setTaskType(educationPaperTask.getTaskType());
stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info)); stringRedisTemplate.opsForValue().set(key, JsonUtils.toJsonString(info));
monitorMapper.insert(info); monitorMapper.insert(info);

View File

@@ -1,24 +1,22 @@
package pc.exam.pp.module.exam.service.paper; package pc.exam.pp.module.exam.service.paper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore; import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
import pc.exam.pp.framework.tenant.core.context.TenantContextHolder; import pc.exam.pp.framework.tenant.core.context.TenantContextHolder;
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo; import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
import pc.exam.pp.module.exam.dal.dataobject.PaperListResponseVo; import pc.exam.pp.module.exam.dal.dataobject.*;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper; import pc.exam.pp.module.exam.dal.mysql.paper.*;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperQu;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperScheme;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperQuMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSchemeMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperTaskMapper;
import pc.exam.pp.module.exam.utils.uuid.IdUtils; import pc.exam.pp.module.exam.utils.uuid.IdUtils;
import java.util.*; import java.util.*;
import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/** /**
* 试卷Service业务层处理 * 试卷Service业务层处理
* *
@@ -31,12 +29,17 @@ public class EducationPaperServiceImpl implements IEducationPaperService
@Autowired @Autowired
private EducationPaperMapper educationPaperMapper; private EducationPaperMapper educationPaperMapper;
@Autowired @Autowired
private EducationPaperParamMapper educationPaperParamMapper;
@Autowired
private EducationPaperSchemeMapper educationPaperSchemeMapper; private EducationPaperSchemeMapper educationPaperSchemeMapper;
@Autowired @Autowired
private EducationPaperTaskMapper educationPaperTaskMapper; private EducationPaperTaskMapper educationPaperTaskMapper;
@Autowired @Autowired
private EducationPaperQuMapper educationPaperQuMapper; private EducationPaperQuMapper educationPaperQuMapper;
@Autowired
private EducationPaperPersonMapper educationPaperPersonMapper;
/** /**
* 查询试卷 * 查询试卷
* *
@@ -257,6 +260,46 @@ public class EducationPaperServiceImpl implements IEducationPaperService
return educationPaperMapper.changeStatus(paperId,status); return educationPaperMapper.changeStatus(paperId,status);
} }
@Override
public PageResult<EducationPaperStuDto> selectStuEducationPaperList(PaperPageVo paperPageVo) {
String taskId = paperPageVo.getTaskId();
List<String> stuIds=educationPaperPersonMapper.selectStuIdByTaskId(taskId);
Long loginUserId = getLoginUserId();
// 判断试卷任务是否包含此学生
if (stuIds.contains(String.valueOf(loginUserId))) {
//
List<EducationPaperStuDto> educationPaperStuDtos=new ArrayList<>();
PageResult<EducationPaper> educationPaperPageResult = educationPaperMapper.selectStuEducationPaperList(paperPageVo);
List<EducationPaper> list = educationPaperPageResult.getList();
if (list!=null&&list.size()>0){
for (EducationPaper educationPaper : list) {
EducationPaperStuDto educationPaperStuDto=new EducationPaperStuDto();
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(educationPaper.getTaskId());
educationPaperStuDto.setPaperId(educationPaper.getPaperId());
educationPaperStuDto.setNum(educationPaper.getNum());
educationPaperStuDto.setTaskId(educationPaper.getTaskId());
educationPaperStuDto.setCounts(educationPaper.getCounts());
educationPaperStuDto.setRollUp(educationPaper.getRollUp());
educationPaperStuDto.setIsAb(educationPaper.getIsAb());
educationPaperStuDto.setEducationPaperParam(educationPaperParam);
educationPaperStuDtos.add(educationPaperStuDto);
}
}
PageResult<EducationPaperStuDto> educationPaperStuDtoPageResult=new PageResult<>();
educationPaperStuDtoPageResult.setList(educationPaperStuDtos);
educationPaperStuDtoPageResult.setTotal(educationPaperPageResult.getTotal());
return educationPaperStuDtoPageResult;
} else {
// 不包含
PageResult<EducationPaperStuDto> educationPaperStuDtoPageResult=new PageResult<>();
return educationPaperStuDtoPageResult;
}
}
} }

View File

@@ -68,6 +68,27 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
@Override @Override
public PageResult<EducationPaperTask> selectEducationPaperTaskList(PaperTaskPageVo educationPaperTask) { public PageResult<EducationPaperTask> selectEducationPaperTaskList(PaperTaskPageVo educationPaperTask) {
PageResult<EducationPaperTask> educationPaperTasks = educationPaperTaskMapper.selectEducationPaperTaskList(educationPaperTask); PageResult<EducationPaperTask> educationPaperTasks = educationPaperTaskMapper.selectEducationPaperTaskList(educationPaperTask);
List<EducationPaperTask> list = educationPaperTasks.getList();
if (list!=null&&list.size()>0){
for (EducationPaperTask paperTask : list) {
int count=0;
List<EducationPaper> educationPapers = educationPaperMapper.selectPaperListByTaskId(paperTask.getTaskId());
if (educationPapers!=null&&educationPapers.size()>0){
for (EducationPaper educationPaper : educationPapers) {
try {
count += Integer.parseInt(educationPaper.getCounts());
} catch (NumberFormatException e) {
// 可选:记录异常或忽略非法数字
System.err.println("无效的 counts 值: " + educationPaper.getCounts());
}
}
}
paperTask.setCount(String.valueOf(count));
}
}
return educationPaperTasks ; return educationPaperTasks ;
} }
@@ -89,6 +110,11 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
educationPaperParam.setUsb("0"); educationPaperParam.setUsb("0");
educationPaperParam.setSaveGrades("0"); educationPaperParam.setSaveGrades("0");
educationPaperParam.setDriver("C"); educationPaperParam.setDriver("C");
educationPaperParam.setIsNumber("1");
educationPaperParam.setIsConnect("0");
educationPaperParam.setIsAnswerId("1");
educationPaperParam.setDirectory("KSWJ"); educationPaperParam.setDirectory("KSWJ");
educationPaperParam.setUploadTime("5"); educationPaperParam.setUploadTime("5");
educationPaperParam.setIsDel("0"); educationPaperParam.setIsDel("0");

View File

@@ -2,6 +2,7 @@ package pc.exam.pp.module.exam.service.paper;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.module.exam.controller.admin.paper.dto.EducationPaperStuDto;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo; import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
import pc.exam.pp.module.exam.dal.dataobject.PaperListResponseVo; import pc.exam.pp.module.exam.dal.dataobject.PaperListResponseVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaper; import pc.exam.pp.module.exam.dal.dataobject.EducationPaper;
@@ -87,5 +88,7 @@ public interface IEducationPaperService
int changeStatus(String paperId, String status); int changeStatus(String paperId, String status);
PageResult<EducationPaperStuDto> selectStuEducationPaperList(PaperPageVo paperPageVo);
} }

View File

@@ -0,0 +1,24 @@
package pc.exam.pp.module.exam.service.stu_paper_file;
import jakarta.validation.Valid;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.module.exam.controller.admin.student.vo.StudentPageReqVO;
import pc.exam.pp.module.exam.controller.admin.student.vo.StudentSaveReqVO;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.dal.dataobject.student.StudentDO;
import java.util.List;
/**
* 学生-试卷-文件 Service 接口
*
* @author rwb
*/
public interface StuPaperFileService {
StuPaperFileDO findByStuIDAndPaperId(Long stuID, String paperID);
void insertStuPaperFile(StuPaperFileDO stuPaperFileDO);
void updateStuPaperFile(StuPaperFileDO stuPaperFileDO);
}

View File

@@ -0,0 +1,35 @@
package pc.exam.pp.module.exam.service.stu_paper_file;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.dal.mysql.student.StuPaperFileMapper;
/**
* 学生-试卷-文件 Service 实现类
*
* @author rwb
*/
@Service
@Validated
public class StuPaperFileServiceImpl implements StuPaperFileService {
@Resource
private StuPaperFileMapper stuPaperFileMapper;
@Override
public StuPaperFileDO findByStuIDAndPaperId(Long stuID, String paperID) {
return stuPaperFileMapper.findByStuIdAndPaperId(stuID, paperID);
}
@Override
public void insertStuPaperFile(StuPaperFileDO stuPaperFileDO) {
stuPaperFileMapper.insert(stuPaperFileDO);
}
@Override
public void updateStuPaperFile(StuPaperFileDO stuPaperFileDO) {
stuPaperFileMapper.updateById(stuPaperFileDO);
}
}

View File

@@ -7,6 +7,9 @@
<resultMap type="EducationPaperParam" id="EducationPaperParamResult"> <resultMap type="EducationPaperParam" id="EducationPaperParamResult">
<result property="paramId" column="param_id" /> <result property="paramId" column="param_id" />
<result property="taskId" column="task_id" /> <result property="taskId" column="task_id" />
<result property="isNumber" column="is_number" />
<result property="isContent" column="is_content" />
<result property="isAnswerId" column="is_answer_id" />
<result property="isExamPassword" column="is_exam_password" /> <result property="isExamPassword" column="is_exam_password" />
<result property="examPassword" column="exam_password" /> <result property="examPassword" column="exam_password" />
<result property="usb" column="usb" /> <result property="usb" column="usb" />
@@ -23,7 +26,7 @@
</resultMap> </resultMap>
<sql id="selectEducationPaperParamVo"> <sql id="selectEducationPaperParamVo">
select param_id, task_id, is_exam_password, exam_password, usb, save_grades, driver, directory, upload_time, is_del,is_repeat ,is_answer,is_look,is_connect,is_session from education_paper_param select param_id, task_id, is_number,is_content,is_answer_id,is_exam_password, exam_password, usb, save_grades, driver, directory, upload_time, is_del,is_repeat ,is_answer,is_look,is_connect,is_session from education_paper_param
</sql> </sql>
<select id="selectEducationPaperParamList" parameterType="EducationPaperParam" resultMap="EducationPaperParamResult"> <select id="selectEducationPaperParamList" parameterType="EducationPaperParam" resultMap="EducationPaperParamResult">
@@ -55,6 +58,9 @@
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="paramId != null">param_id,</if> <if test="paramId != null">param_id,</if>
<if test="taskId != null">task_id,</if> <if test="taskId != null">task_id,</if>
<if test="isNumber != null">is_number,</if>
<if test="isContent != null">is_content,</if>
<if test="isAnswerId != null">is_answer_id,</if>
<if test="isExamPassword != null">is_exam_password,</if> <if test="isExamPassword != null">is_exam_password,</if>
<if test="examPassword != null">exam_password,</if> <if test="examPassword != null">exam_password,</if>
<if test="usb != null">usb,</if> <if test="usb != null">usb,</if>
@@ -73,6 +79,9 @@
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="paramId != null">#{paramId},</if> <if test="paramId != null">#{paramId},</if>
<if test="taskId != null">#{taskId},</if> <if test="taskId != null">#{taskId},</if>
<if test="isNumber != null">#{isNumber},</if>
<if test="isContent != null">#{isContent},</if>
<if test="isAnswerId != null">#{isAnswerId},</if>
<if test="isExamPassword != null">#{isExamPassword},</if> <if test="isExamPassword != null">#{isExamPassword},</if>
<if test="examPassword != null">#{examPassword},</if> <if test="examPassword != null">#{examPassword},</if>
<if test="usb != null">#{usb},</if> <if test="usb != null">#{usb},</if>
@@ -94,6 +103,9 @@
update education_paper_param update education_paper_param
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="taskId != null">task_id = #{taskId},</if> <if test="taskId != null">task_id = #{taskId},</if>
<if test="isNumber != null">is_number = #{isNumber},</if>
<if test="isContent != null">is_content = #{isContent},</if>
<if test="isAnswerId != null">is_answer_id = #{isAnswerId},</if>
<if test="isExamPassword != null">is_exam_password = #{isExamPassword},</if> <if test="isExamPassword != null">is_exam_password = #{isExamPassword},</if>
<if test="examPassword != null">exam_password = #{examPassword},</if> <if test="examPassword != null">exam_password = #{examPassword},</if>
<if test="usb != null">usb = #{usb},</if> <if test="usb != null">usb = #{usb},</if>

View File

@@ -107,6 +107,10 @@
ORDER BY s.id DESC ORDER BY s.id DESC
</select> </select>
<select id="selectStuIdByTaskId" resultType="java.lang.String">
select person_id from education_paper_person where task_id=#{taskId}
</select>
<insert id="insertEducationPaperPerson" parameterType="EducationPaperPerson"> <insert id="insertEducationPaperPerson" parameterType="EducationPaperPerson">

View File

@@ -113,6 +113,12 @@
<select id="selectStuClassNameByClassId" resultType="java.lang.String"> <select id="selectStuClassNameByClassId" resultType="java.lang.String">
select name from exam_class where id=#{classId} select name from exam_class where id=#{classId}
</select> </select>
<select id="selectEducationPaperTaskByTaskType"
resultMap="EducationPaperTaskResult">
<include refid="selectEducationPaperTaskVo"/>
where task_type = #{id}
and deleted='0'
</select>
<insert id="insertEducationPaperTask" parameterType="EducationPaperTask"> <insert id="insertEducationPaperTask" parameterType="EducationPaperTask">

View File

@@ -38,7 +38,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where> <where>
<if test="quId != null "> and qu_id = #{quId}</if> <if test="quId != null "> and qu_id = #{quId}</if>
</where> </where>
and (file_type = '0' or file_type ='1')
</select> </select>
<insert id="insertSysFile" parameterType="SysFileUpload"> <insert id="insertSysFile" parameterType="SysFileUpload">

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pc.exam.pp.module.exam.dal.mysql.student.StuPaperFileMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<select id="findByStuIdAndPaperId" resultType="pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO">
SELECT * FROM exam_stu_paper_fileurl WHERE stu_id = #{stuId} AND paper_id = #{paperId}
</select>
</mapper>

View File

@@ -73,4 +73,11 @@ public interface ErrorCodeConstants {
// ========== 试卷参数 1-001-401-000 ========== // ========== 试卷参数 1-001-401-000 ==========
ErrorCode DEMO03_PAPER_SESSION_EXISTS = new ErrorCode(1_001_401_001, "请开启考场设置"); ErrorCode DEMO03_PAPER_SESSION_EXISTS = new ErrorCode(1_001_401_001, "请开启考场设置");
// ========== 监控管理 1-001-606-000 ==========
ErrorCode DEMO03_MONITOR_TIME_EXISTS = new ErrorCode(1-001-606-001, "该考试不在考场时间范围内!");
ErrorCode DEMO03_MONITOR_SESSION_EXISTS = new ErrorCode(1-001-606-002, "考生状态未在考试中!请联系管理员");
} }

View File

@@ -124,6 +124,12 @@
<groupId>org.apache.tika</groupId> <groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 --> <artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
</dependency> </dependency>
<dependency>
<groupId>pc.exam.gg</groupId>
<artifactId>exam-module-exam-biz</artifactId>
<version>2.4.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>

View File

@@ -66,6 +66,14 @@ public class FileController {
return success(true); return success(true);
} }
@PostMapping("/upload_stu")
@Operation(summary = "上传学生考试文件", description = "模式三后端上传文件带有学生ID")
public CommonResult<String> uploadStuFile(StuFileUploadReqVO uploadReqVO) throws Exception {
MultipartFile file = uploadReqVO.getFile();
String path = uploadReqVO.getPath();
return success(fileService.createStuFile(uploadReqVO.getStuId(), uploadReqVO.getPaperId(), file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
}
@GetMapping("/{configId}/get/**") @GetMapping("/{configId}/get/**")
@PermitAll @PermitAll
@Operation(summary = "下载文件") @Operation(summary = "下载文件")

View File

@@ -0,0 +1,25 @@
package pc.exam.pp.module.infra.controller.admin.file.vo.file;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
@Schema(description = "管理后台 - 上传文件 Request VO")
@Data
public class StuFileUploadReqVO {
@Schema(description = "文件附件", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "文件附件不能为空")
private MultipartFile file;
@Schema(description = "文件附件", example = "examyuanma.png")
private String path;
@Schema(description = "学生ID")
private Long stuId;
@Schema(description = "试卷ID")
private String paperId;
}

View File

@@ -31,6 +31,16 @@ public interface FileService {
*/ */
String createFile(String name, String path, byte[] content); String createFile(String name, String path, byte[] content);
/**
* 保存文件,并返回文件的访问路径
*
* @param name 文件名称
* @param path 文件路径
* @param content 文件内容
* @return 文件路径
*/
String createStuFile(Long stuId, String paperId, String name, String path, byte[] content);
/** /**
* 创建文件 * 创建文件
* *

View File

@@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil;
import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.common.util.io.FileUtils; import pc.exam.pp.framework.common.util.io.FileUtils;
import pc.exam.pp.framework.common.util.object.BeanUtils; import pc.exam.pp.framework.common.util.object.BeanUtils;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
import pc.exam.pp.module.infra.framework.file.core.client.FileClient; import pc.exam.pp.module.infra.framework.file.core.client.FileClient;
import pc.exam.pp.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO; import pc.exam.pp.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
import pc.exam.pp.module.infra.framework.file.core.utils.FileTypeUtils; import pc.exam.pp.module.infra.framework.file.core.utils.FileTypeUtils;
@@ -34,6 +36,9 @@ public class FileServiceImpl implements FileService {
@Resource @Resource
private FileMapper fileMapper; private FileMapper fileMapper;
@Resource
private StuPaperFileService stuPaperFileService;
@Override @Override
public PageResult<FileDO> getFilePage(FilePageReqVO pageReqVO) { public PageResult<FileDO> getFilePage(FilePageReqVO pageReqVO) {
return fileMapper.selectPage(pageReqVO); return fileMapper.selectPage(pageReqVO);
@@ -69,6 +74,53 @@ public class FileServiceImpl implements FileService {
return url; return url;
} }
@Override
@SneakyThrows
public String createStuFile(Long stuId, String paperId, String name, String path, byte[] content) {
// 计算默认的 path 名
String type = FileTypeUtils.getMineType(content, name);
if (StrUtil.isEmpty(path)) {
path = FileUtils.generatePath(content, name);
}
// 如果 name 为空,则使用 path 填充
if (StrUtil.isEmpty(name)) {
name = path;
}
// 上传到文件存储器
FileClient client = fileConfigService.getMasterFileClient();
Assert.notNull(client, "客户端(master) 不能为空");
String url = client.upload(content, path, type);
// 保存到数据库
FileDO file = new FileDO();
file.setConfigId(client.getId());
file.setName(name);
file.setPath(path);
file.setUrl(url);
file.setType(type);
file.setSize(content.length);
fileMapper.insert(file);
// 需要更新学生表
// 1、先查询学生试卷 是否已经存在数据
StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId);
if (stuPaperFileDO == null) {
// 说明没有上传过,需要新增进去
StuPaperFileDO stuPaperFile = new StuPaperFileDO();
stuPaperFile.setPaperId(paperId);
stuPaperFile.setStuId(stuId);
stuPaperFile.setUrl(url);
stuPaperFileService.insertStuPaperFile(stuPaperFile);
} else {
// 说明已经上传过判断url是否一致不一致得需要进行更新操作
if (!url.equals(stuPaperFileDO.getUrl())) {
stuPaperFileDO.setUrl(url);
stuPaperFileService.updateStuPaperFile(stuPaperFileDO);
}
}
return url;
}
@Override @Override
public Long createFile(FileCreateReqVO createReqVO) { public Long createFile(FileCreateReqVO createReqVO) {
FileDO file = BeanUtils.toBean(createReqVO, FileDO.class); FileDO file = BeanUtils.toBean(createReqVO, FileDO.class);

View File

@@ -1,4 +1,26 @@
package pc.exam.pp.module.judgement.controller.admin.autoTools; package pc.exam.pp.module.judgement.controller.admin.autoTools;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuPaperReqVo;
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
@RestController
@RequestMapping("/tool")
@Tag( name = "测试判分")
@Validated
public class AutoToolsController { public class AutoToolsController {
@Resource
private AutoToolsService autoToolsService;
@GetMapping("/get")
public CommonResult<Double> get(StuPaperReqVo stuPaperReqVo) {
return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId());
}
} }

View File

@@ -5,15 +5,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@Data @Data
public class StudentUploadFileZipReqVo { public class StuPaperReqVo {
@Schema(description = "学号") @Schema(description = "学号")
private Long studentId; private Long stuId;
@Schema(description = "试卷号") @Schema(description = "试卷号")
private String paperId; private String paperId;
@Schema(description = "上传文件路径")
private String filePath;
} }

View File

@@ -1,5 +1,7 @@
package pc.exam.pp.module.judgement.service.auto_tools; package pc.exam.pp.module.judgement.service.auto_tools;
import pc.exam.pp.framework.common.pojo.CommonResult;
public interface AutoToolsService { public interface AutoToolsService {
@@ -23,4 +25,12 @@ public interface AutoToolsService {
* @return 解压后的目录 * @return 解压后的目录
*/ */
String unzipToNamedFolder(String zipFilePath); String unzipToNamedFolder(String zipFilePath);
/**
* 判分
* @param stuId 学号
* @param paperId 试卷ID
* @return 分数
*/
CommonResult<Double> judgementScore(Long stuId, String paperId);
} }

View File

@@ -1,6 +1,16 @@
package pc.exam.pp.module.judgement.service.auto_tools; package pc.exam.pp.module.judgement.service.auto_tools;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pc.exam.pp.framework.common.exception.ErrorCode;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.service.question.IExamQuestionService;
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.judgement.service.c_programming.JudgementService;
import java.io.*; import java.io.*;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@@ -11,6 +21,14 @@ import java.util.zip.ZipInputStream;
@Service @Service
public class AutoToolsServiceImpl implements AutoToolsService{ public class AutoToolsServiceImpl implements AutoToolsService{
@Resource
private StuPaperFileService stuPaperFileService;
@Resource
ConfigService configService;
@Resource
IExamQuestionService examQuestionService;
@Resource
JudgementService judgementService;
@Override @Override
public String downloadStudentFile(String fileUrl, String filePath) { public String downloadStudentFile(String fileUrl, String filePath) {
@@ -94,4 +112,66 @@ public class AutoToolsServiceImpl implements AutoToolsService{
return null; return null;
} }
} }
@Override
public CommonResult<Double> judgementScore(Long stuId, String paperId) {
double score = 0;
// 1、通过学号,试卷ID查询文件路径
StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId);
// 2、判断文件路径是否存在
if (stuPaperFileDO == null) {
return CommonResult.error(100031, "试题文件没有上传,无法判分!");
}
// 3、下载文件
// 获取平台文件参数
ConfigDO config = configService.getConfigByKey("file_down_path");
String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue());
// 4、获取到得是zip文件需要解压
String stuFilePath = unzipToNamedFolder(patn);
// 5、解压之后得文件获取文件夹和文件
File folder = new File(stuFilePath);
File[] files = folder.listFiles();
String stu_files = null;
// 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容)
if (files == null) return CommonResult.error(100032, "1、试题文件上传目录不正确");
if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传目录不正确");
if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传目录不正确");
// 判断学号是否正确
if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常");
// 5.2、查询试题ID
File folders = new File(files[0].getPath());
File[] filess = folders.listFiles();
if (filess == null) return CommonResult.error(100036, "4、试卷文件上传目录不正确");
if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传目录不正确");
if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传目录不正确");
// 判断学号是否正确
if (!files[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常");
// 5.3、查询出来所有试题
File qu_files = new File(filess[0].getPath());
// 所有试题文件夹
File[] filess_qu = qu_files.listFiles();
if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!");
for (File file : filess_qu) {
// 6、根据试题ID查询试题详情
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(file.getName());
// 7、进行对应得判分
// --- 7.1、查询试题文件
File qu_file = new File(file.getPath());
File[] qu_file_list = qu_files.listFiles();
if (qu_file_list == null) continue;
// --- 7.2、通过文件名称进行判分
for (File file_one : qu_file_list) {
// 判断名称 类似于 C语言程序设计。
if (file_one.getName().split("\\.")[0].equals(examQuestion.getCourseName()+examQuestion.getSubjectName())) {
double c_score = judgementService.ProgrammingC(15.0, file.getPath(), file_one.getName(), examQuestion);
score += c_score;
break;
}
// wps 类型存在多级文文件夹,需要个性化设置
// if ()
}
}
return CommonResult.success(score);
}
} }

View File

@@ -12,11 +12,12 @@ public interface JudgementService {
/** /**
* 程序设计判分 * 程序设计判分
* @param examQuestion 程序设计题内容 * @param examQuestion 程序设计题内容
* @param path 文件路径 * @param fileName 文件名称
* @param pathC 文件路径 C语言文件
* @param score 分数 * @param score 分数
* @return 返回判分 * @return 返回判分
*/ */
public double ProgrammingC(double score, String path, ExamQuestion examQuestion); public double ProgrammingC(double score, String pathC, String fileName, ExamQuestion examQuestion);
/** /**

View File

@@ -21,11 +21,11 @@ public class JudgementServiceImpl implements JudgementService
/** /**
* 程序设计判分 * 程序设计判分
* @param examQuestion 程序设计题内容 * @param examQuestion 程序设计题内容
* @param path 文件路径 * @param fileName 文件名称
* @param score 分数 * @param score 分数
* @return 返回判分 * @return 返回判分
*/ */
public double ProgrammingC(double score, String path, ExamQuestion examQuestion) { public double ProgrammingC(double score, String pathC, String fileName, ExamQuestion examQuestion) {
// 关键字比对,超过权重-测试用例/运行(测试用例全对,直接满分-不全对)-结果,不超过权重只给关键字几个的分 // 关键字比对,超过权重-测试用例/运行(测试用例全对,直接满分-不全对)-结果,不超过权重只给关键字几个的分
// 获取该题有多少分 // 获取该题有多少分
@@ -61,11 +61,9 @@ public class JudgementServiceImpl implements JudgementService
// 编译分数分数占比 // 编译分数分数占比
double pass_score = score * is_pass_score; double pass_score = score * is_pass_score;
// 试卷其中有C语言的试题
String path_c = path + "/" + examQuestion.getQuBankName();
// 创建log文件txt用于记录 // 创建log文件txt用于记录
LogFileUtils.createFile(path_c + "/log.txt"); LogFileUtils.createFile(pathC + "/log.txt");
String code = JudgementCUtils.readFile(path_c, examQuestion.getQuId()+".txt"); String code = JudgementCUtils.readFile(pathC, fileName);
LogFileUtils.writeLine("✅ 系统开始读取文件:" + code); LogFileUtils.writeLine("✅ 系统开始读取文件:" + code);
if (code == null) { if (code == null) {
// 如果没有读到源码 // 如果没有读到源码

View File

@@ -2,8 +2,10 @@ package pc.exam.pp.module.judgement.service.wps_word;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@@ -20,4 +22,14 @@ public interface JudgementWpsWordService {
* @throws Exception 异常 * @throws Exception 异常
*/ */
public List<WordVO> ProgrammingWpsWord(String path) throws Exception; public List<WordVO> ProgrammingWpsWord(String path) throws Exception;
/**
* 读取考生文件,与题型中要求进行判断
* @param path 文件路径
* @param examQuestion 试题参数
* @param sorce 试题分数
* @return 得分
* @throws Exception 异常
*/
public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception;
} }

View File

@@ -4,6 +4,8 @@ package pc.exam.pp.module.judgement.service.wps_word;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService; import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO; import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
@@ -14,6 +16,8 @@ import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils;
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
import java.io.File; import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List; import java.util.List;
@Service @Service
@@ -46,5 +50,31 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
return margins1; return margins1;
} }
@Override
public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception {
BigDecimal wps_word_sorce = new BigDecimal(0);
// 1、查询Word考点tree
WordListReqVO wordListReqVO = new WordListReqVO();
wordListReqVO.setBelongTo(0);
List<WpsWordLinkDO> list = wpsWordLinkMapper.selectList(wordListReqVO);
// 2、docx文件读取并返回考点及说明信息
List<WordVO> margins1 = WpsWordUtils.wps_word(path, list);
// 3、获取答案得组成
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
// 4、进行关联判断
for (ExamQuestionAnswer examQuestionAnswer : answerList) {
for (WordVO wordVO : margins1) {
for (String str : wordVO.getExamKeynote()) {
if (str.equals(examQuestionAnswer.getContent())) {
// 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重
BigDecimal one_sorce = sorce.multiply(new BigDecimal(examQuestionAnswer.getScoreRate())).setScale(2, RoundingMode.HALF_UP);
wps_word_sorce = wps_word_sorce.add(one_sorce);
}
}
}
}
return wps_word_sorce;
}
} }

View File

@@ -185,5 +185,5 @@ public interface ErrorCodeConstants {
ErrorCode WORD_PARENT_IS_CHILD = new ErrorCode(1_002_030_007, "不能设置自己的子WORD节点为父WORD节点"); ErrorCode WORD_PARENT_IS_CHILD = new ErrorCode(1_002_030_007, "不能设置自己的子WORD节点为父WORD节点");
ErrorCode MONITOR_NOT_EXISTS = new ErrorCode(1_003_301_001, "id为空"); ErrorCode MONITOR_NOT_EXISTS = new ErrorCode(1_003_301_001, "找不到值!");
} }

View File

@@ -47,7 +47,7 @@ spring:
primary: master primary: master
datasource: datasource:
master: master:
url: jdbc:mysql://127.0.0.1:3306/pc-exam?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例 url: jdbc:mysql://rm-bp1a44uap1mm20980mo.mysql.rds.aliyuncs.com:3306/pc-exam?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # MySQL Connector/J 5.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
@@ -55,8 +55,8 @@ spring:
# url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
# url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例 # url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例
username: root username: pc_exam
password: 123 password: Pcexam123
# username: sa # SQL Server 连接的示例 # username: sa # SQL Server 连接的示例
# password: Exam@2024 # SQL Server 连接的示例 # password: Exam@2024 # SQL Server 连接的示例
# username: SYSDBA # DM 连接的示例 # username: SYSDBA # DM 连接的示例