Accept Merge Request #63: (hyc -> master)
Merge Request: 【新增】mysql,win文件读取文件设置考点后端接口,题型增加判分规则 Created By: @华允传 Accepted By: @华允传 URL: https://g-iswv8783.coding.net/p/education/d/pengchen-exam-java/git/merge/63?initial=true
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.getpoints;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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.exam.service.getpoints.ExamGetPointsService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/exam/getopints")
|
||||
public class GetPointsController {
|
||||
|
||||
@Autowired
|
||||
private ExamGetPointsService examGetPointsService;
|
||||
|
||||
/**
|
||||
* 得出文件操作考点
|
||||
* @return 得分
|
||||
*/
|
||||
@PostMapping("/get_filePoint")
|
||||
//todo 后期需要素材文件和答案文件的 父目录 如:D:/exam/3/shucai,D:/exam/3/win
|
||||
public CommonResult get_file_point() throws IOException {
|
||||
return CommonResult.success(examGetPointsService.get_file_point());
|
||||
}
|
||||
@PostMapping("/get_mysql_point")
|
||||
//todo 后期需要素材文件和答案文件的 父目录 如:D:/exam/3/shucai,D:/exam/3/win
|
||||
public CommonResult get_mysql_point() throws IOException {
|
||||
return CommonResult.success(examGetPointsService.get_mysql_point());
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.paper.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||
import pc.exam.pp.framework.common.util.object.BeanUtils;
|
||||
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialRolesVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtListReqVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.knowledge.ExamKnowledgePoints;
|
||||
@@ -154,4 +155,19 @@ public class ExamSpecialtyController{
|
||||
}
|
||||
return success(examSpecialtyService.deleteExamSpecialtyBySpIds(spIds));
|
||||
}
|
||||
@PostMapping("/setRole")
|
||||
public CommonResult setRole(@RequestBody SpecialRolesVo specialRolesVo) {
|
||||
System.out.println(specialRolesVo);
|
||||
ExamSpecialty examSpecialty = examSpecialtyService.selectExamSpecialtyBySpId(Long.valueOf(specialRolesVo.getId()));
|
||||
examSpecialty.setRoles(specialRolesVo.getRoles());
|
||||
examSpecialtyService.updateExamSpecialty(examSpecialty);
|
||||
return success("设置成功");
|
||||
}
|
||||
@GetMapping(value = "/getRole/{id}")
|
||||
public CommonResult getRole(@PathVariable("id") String id) {
|
||||
String roles= examSpecialtyService.getRoleById(id);
|
||||
|
||||
return success(Integer.parseInt(roles));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package pc.exam.pp.module.exam.controller.admin.specialty.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SpecialRolesVo {
|
||||
private String id;
|
||||
private String roles;
|
||||
}
|
@@ -22,4 +22,6 @@ public class SpecialtyQueryVo {
|
||||
private Integer orderNum;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String roles;
|
||||
}
|
||||
|
@@ -59,4 +59,6 @@ public class EducationPaperTask extends TenantBaseDO
|
||||
@TableField(exist = false)
|
||||
EducationPaperParam educationPaperParam;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String score;
|
||||
}
|
||||
|
@@ -1,9 +1,11 @@
|
||||
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.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.v3.oas.annotations.info.Contact;
|
||||
import jdk.dynalink.linker.LinkerServices;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -13,6 +15,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import pc.exam.pp.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 试题答案选项(hyc)对象 exam_question_answer
|
||||
*
|
||||
@@ -61,6 +65,18 @@ public class ExamQuestionAnswer
|
||||
// @Excel(name = "排序")
|
||||
private String sort;
|
||||
|
||||
@TableField(exist = false)
|
||||
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
|
||||
private List<ExamMysqlKeyword> examMysqlKeywordList;
|
||||
|
||||
|
||||
public ExamQuestionAnswer(String answerId, String quId, String isRight, String image, String content, String contentIn, String scoreRate, String sort) {
|
||||
this.answerId = answerId;
|
||||
this.quId = quId;
|
||||
this.isRight = isRight;
|
||||
this.image = image;
|
||||
this.content = content;
|
||||
this.contentIn = contentIn;
|
||||
this.scoreRate = scoreRate;
|
||||
this.sort = sort;
|
||||
}
|
||||
}
|
||||
|
@@ -34,4 +34,7 @@ public class ExamSpecialty extends TenantBaseDO {
|
||||
|
||||
/** 子树数量 */
|
||||
private Long treeNum;
|
||||
|
||||
/** 判分规则*/
|
||||
private String roles;
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package pc.exam.pp.module.exam.dal.mysql.monitor;
|
||||
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import pc.exam.pp.framework.common.pojo.PageResult;
|
||||
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
|
||||
@@ -49,4 +50,8 @@ return selectPage(reqVO, new LambdaQueryWrapperX<MonitorDO>()
|
||||
}
|
||||
|
||||
|
||||
String selectByStuIdAndTaskIdTop(@Param("stuId")Long stuId, @Param("taskId") String taskId);
|
||||
|
||||
String selectByStuIdAndTaskIdNew(Long stuId, String taskId);
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package pc.exam.pp.module.exam.dal.mysql.mysqlkeyword;
|
||||
|
||||
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamMysqlKeyword;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MYSQL判分关键字考点 Mapper
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Mapper
|
||||
public interface MysqlKeywordMapper extends BaseMapperX<ExamMysqlKeyword> {
|
||||
|
||||
|
||||
void deleteByAnswerId(String answerId);
|
||||
|
||||
}
|
@@ -71,4 +71,8 @@ public interface ExamQuestionAnswerMapper extends BaseMapperX<ExamQuestionAnswe
|
||||
public int deleteExamQuestionAnswerByQuesId(String firstQuId);
|
||||
|
||||
public int deleteExamQuestionAnswerByQuesIds(@Param("ids") String[] ids);
|
||||
|
||||
List<String> selectExamQuestionAnswerIdByQuId(String quId);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -122,4 +122,8 @@ public interface ExamQuestionMapper extends BaseMapperX<ExamQuestion>
|
||||
int selectExamQuestionCountByQuId(String quId);
|
||||
|
||||
List<TenantVo> getSchoolNameNaPage();
|
||||
|
||||
long selectTenantId();
|
||||
|
||||
|
||||
}
|
||||
|
@@ -96,4 +96,6 @@ public interface ExamSpecialtyMapper extends BaseMapperX<ExamSpecialty>
|
||||
public int deleteExamSpecialtyBySpIds(Long[] spIds);
|
||||
|
||||
|
||||
String getRoleById(String id);
|
||||
|
||||
}
|
||||
|
@@ -2,9 +2,12 @@ package pc.exam.pp.module.exam.job;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
import pc.exam.pp.framework.quartz.core.handler.JobHandler;
|
||||
import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
|
||||
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
|
||||
import pc.exam.pp.module.exam.service.question.IExamQuestionService;
|
||||
import pc.exam.pp.module.exam.utils.rabbitmq.RabbitmqUtils;
|
||||
@@ -21,44 +24,55 @@ public class QuestionDownJob implements JobHandler {
|
||||
private ExamQuestionMapper examQuestionMapper;
|
||||
@Resource
|
||||
private IExamQuestionService examQuestionService;
|
||||
@Value("${server.role}")
|
||||
private String serverRole;
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
if ("center".equals(serverRole)){
|
||||
List<String> queueNames= examQuestionMapper.seleAllQueueName();
|
||||
log.info(queueNames.toString()+"所有学校队列名");
|
||||
if (queueNames!=null){
|
||||
List<String> failedQueues = new ArrayList<>();
|
||||
List<String> successQueues = new ArrayList<>();
|
||||
List<String> failedQueues1 = new ArrayList<>();
|
||||
List<String> successQueues2 = new ArrayList<>();
|
||||
for (String queueName : queueNames) {
|
||||
boolean examQuestionToRabbitMQ = rabbitMqService.connectSchool(queueName);
|
||||
if (!examQuestionToRabbitMQ) {
|
||||
failedQueues.add(queueName);
|
||||
}else {
|
||||
successQueues.add(queueName);
|
||||
}
|
||||
}
|
||||
for (String queueName : successQueues) {
|
||||
try {
|
||||
boolean examQuestionToRabbitMQ = examQuestionService.getExamQuestionToRabbitMQ(queueName);
|
||||
if (!examQuestionToRabbitMQ) {
|
||||
failedQueues1.add(queueName);
|
||||
} else {
|
||||
successQueues2.add(queueName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("拉取队列 {} 时异常:{}", queueName, e.getMessage());
|
||||
failedQueues1.add(queueName);
|
||||
}
|
||||
}
|
||||
log.info(failedQueues.toString()+"连接失败的学校");
|
||||
log.info(successQueues.toString()+"连接成功的学校");
|
||||
log.info(failedQueues1.toString()+"拉取失败的学校");
|
||||
log.info(successQueues2.toString()+"拉取成功的学校");
|
||||
rabbitMqService.disconnect();
|
||||
}
|
||||
}else {
|
||||
System.out.println("不走定时任务测试==========================");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List<String> queueNames= examQuestionMapper.seleAllQueueName();
|
||||
log.info(queueNames.toString()+"所有学校队列名");
|
||||
if (queueNames!=null){
|
||||
List<String> failedQueues = new ArrayList<>();
|
||||
List<String> successQueues = new ArrayList<>();
|
||||
List<String> failedQueues1 = new ArrayList<>();
|
||||
List<String> successQueues2 = new ArrayList<>();
|
||||
for (String queueName : queueNames) {
|
||||
boolean examQuestionToRabbitMQ = rabbitMqService.connectSchool(queueName);
|
||||
if (!examQuestionToRabbitMQ) {
|
||||
failedQueues.add(queueName);
|
||||
}else {
|
||||
successQueues.add(queueName);
|
||||
}
|
||||
}
|
||||
for (String queueName : successQueues) {
|
||||
try {
|
||||
boolean examQuestionToRabbitMQ = examQuestionService.getExamQuestionToRabbitMQ(queueName);
|
||||
if (!examQuestionToRabbitMQ) {
|
||||
failedQueues1.add(queueName);
|
||||
} else {
|
||||
successQueues2.add(queueName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("拉取队列 {} 时异常:{}", queueName, e.getMessage());
|
||||
failedQueues1.add(queueName);
|
||||
}
|
||||
}
|
||||
log.info(failedQueues.toString()+"连接失败的学校");
|
||||
log.info(successQueues.toString()+"连接成功的学校");
|
||||
log.info(failedQueues1.toString()+"拉取失败的学校");
|
||||
log.info(successQueues2.toString()+"拉取成功的学校");
|
||||
rabbitMqService.disconnect();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,15 +0,0 @@
|
||||
package pc.exam.pp.module.exam.service.getpoints;
|
||||
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface ExamGetPointsService {
|
||||
|
||||
|
||||
|
||||
List<ExamQuestionAnswer> get_file_point() throws IOException;
|
||||
|
||||
List<ExamQuestionAnswer> get_mysql_point();
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
package pc.exam.pp.module.exam.service.getpoints;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
import pc.exam.pp.module.exam.utils.file.GetDifferencesBetweenFolders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ExamGetPointsServiceImpl implements ExamGetPointsService{
|
||||
|
||||
static final String BASE_DIR = "D:/exam/3/";
|
||||
@Override
|
||||
public List<ExamQuestionAnswer> get_file_point() throws IOException {
|
||||
List<ExamQuestionAnswer> answerList = new ArrayList<>();
|
||||
AtomicInteger sortCounter = new AtomicInteger(1); // 计数器
|
||||
String path1 = BASE_DIR + "shucai";
|
||||
String path2 = BASE_DIR + "win";
|
||||
|
||||
// 获取 shucai 和 win 文件夹的差异
|
||||
Map<String, String> differences = GetDifferencesBetweenFolders.getDifferencesBetweenFolders(path1, path2);
|
||||
|
||||
List<ExamQuestionAnswer> formattedDifferences = differences.entrySet().stream()
|
||||
.map(entry -> {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
ExamQuestionAnswer answer = new ExamQuestionAnswer();
|
||||
answer.setContent(key); // 设置文件路径
|
||||
answer.setScoreRate("1");
|
||||
//这里设置answer的排序,按照循环次数来
|
||||
answer.setSort(String.valueOf(sortCounter.getAndIncrement())); // 按顺序设置排序值
|
||||
if (value.startsWith("仅存在于 "+path1)) {
|
||||
answer.setContentIn("考察删除");
|
||||
} else if (value.startsWith("仅存在于 "+path2)) {
|
||||
answer.setContentIn("考察名称");
|
||||
} else if (value.startsWith("属性不同")) {
|
||||
answer.setContentIn("考察属性");
|
||||
// answer.setContent(key + " -> " + value.split(" vs ")[1]); // 设置属性信息
|
||||
}
|
||||
return answer;
|
||||
})
|
||||
.sorted(Comparator.comparingInt(answer -> Integer.parseInt(answer.getSort()))) // 按 sort 排序
|
||||
.collect(Collectors.toList());
|
||||
answerList.addAll(formattedDifferences);
|
||||
|
||||
return answerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExamQuestionAnswer> get_mysql_point() {
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -177,7 +177,7 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
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));
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
package pc.exam.pp.module.exam.service.paper;
|
||||
import java.sql.Time;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -19,12 +20,14 @@ import pc.exam.pp.module.exam.controller.admin.paper.vo.ExamPersonVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.SessionStuPageReqVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.StudentSessionReqVO;
|
||||
import pc.exam.pp.module.exam.controller.admin.student.vo.StudentPageReqVO;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperParam;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperPerson;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperSession;
|
||||
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.student.StudentDO;
|
||||
import pc.exam.pp.module.exam.dal.mysql.monitor.MonitorMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperParamMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperPersonMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSessionMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperTaskMapper;
|
||||
@@ -57,6 +60,8 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
|
||||
private EducationPaperSessionMapper educationPaperSessionMapper;
|
||||
@Resource
|
||||
private MonitorMapper monitorMapper;
|
||||
@Resource
|
||||
private EducationPaperParamMapper educationPaperParamMapper;
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
/**
|
||||
@@ -200,10 +205,11 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
|
||||
monitorMapper.updateById(info);
|
||||
|
||||
|
||||
} else if (existing == null) {
|
||||
}
|
||||
if (existing == null) {
|
||||
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId);
|
||||
|
||||
String name= educationPaperTaskMapper.selectEducationPaperTaskNameByid(taskId);
|
||||
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
|
||||
|
||||
EducationPaperPerson educationPaperPerson=new EducationPaperPerson();
|
||||
String key = "userCache:" + taskId+":"+studentId;
|
||||
@@ -215,6 +221,11 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
|
||||
info.setStuId(studentId);
|
||||
info.setUsername(personRepDto.getUsername());
|
||||
info.setNickname(personRepDto.getNickname());
|
||||
//判断是否开启测评时长限制
|
||||
if ("0".equals(educationPaperParam.getIsTime())){
|
||||
Time examTime = educationPaperParam.getExamTime();
|
||||
info.setRemainingTime((long) examTime.toLocalTime().toSecondOfDay());
|
||||
}
|
||||
//设置学生班级
|
||||
if (StringUtils.isNotBlank(personRepDto.getClassId().toString())){
|
||||
String className=educationPaperTaskMapper.selectStuClassNameByClassId(personRepDto.getClassId());
|
||||
|
@@ -16,6 +16,7 @@ import pc.exam.pp.module.exam.controller.admin.paper.vo.ExamPaperVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo;
|
||||
import pc.exam.pp.module.exam.controller.admin.paper.vo.StuInfoPaper;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.*;
|
||||
import pc.exam.pp.module.exam.dal.mysql.monitor.MonitorMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.paper.*;
|
||||
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.question.SysFileMapper;
|
||||
@@ -58,6 +59,8 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
|
||||
|
||||
@Autowired
|
||||
private SysFileMapper sysFileMapper;
|
||||
@Autowired
|
||||
private MonitorMapper monitorMapper;
|
||||
//@Autowired
|
||||
//private ExamQuestionMapper
|
||||
|
||||
@@ -441,6 +444,8 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
|
||||
|
||||
@Override
|
||||
public PageResult<EducationPaperTask> selectEducationPaperTaskListByStu(PaperTaskPageVo educationPaperTask) {
|
||||
String taskType = educationPaperTask.getTaskType();
|
||||
|
||||
PageResult<EducationPaperTask> educationPaperTasks = educationPaperTaskMapper.selectEducationPaperTaskList(educationPaperTask);
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
|
||||
@@ -450,6 +455,32 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
|
||||
list = list.stream()
|
||||
.filter(task -> taskIds.contains(task.getTaskId()))
|
||||
.collect(Collectors.toList());
|
||||
if ("0".equals(taskType)){
|
||||
for (EducationPaperTask paperTask : list) {
|
||||
String taskId = paperTask.getTaskId();
|
||||
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
|
||||
//最高成绩
|
||||
Long stuId= SecurityFrameworkUtils.getLoginUserId();
|
||||
if ("0".equals(educationPaperParam.getSaveGrades())){
|
||||
|
||||
String score= monitorMapper.selectByStuIdAndTaskIdTop(stuId,taskId);
|
||||
if (StringUtils.isNotBlank(score)){
|
||||
paperTask.setScore(score);
|
||||
}else {
|
||||
paperTask.setScore("0.0");
|
||||
}
|
||||
}else {
|
||||
String score= monitorMapper.selectByStuIdAndTaskIdNew(stuId,taskId);
|
||||
if (StringUtils.isNotBlank(score)){
|
||||
paperTask.setScore(score);
|
||||
}else {
|
||||
paperTask.setScore("0.0");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
educationPaperTasks.setList(list);
|
||||
return educationPaperTasks;
|
||||
}else {
|
||||
|
@@ -77,4 +77,6 @@ public interface ExamSpecialtyService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteExamSpecialtyBySpId(Long spId);
|
||||
|
||||
String getRoleById(String id);
|
||||
}
|
@@ -120,4 +120,9 @@ public class ExamSpecialtyServiceImpl implements ExamSpecialtyService {
|
||||
{
|
||||
return examSpecialtyMapper.deleteExamSpecialtyBySpId(spId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoleById(String id) {
|
||||
return examSpecialtyMapper.getRoleById(id);
|
||||
}
|
||||
}
|
||||
|
@@ -89,6 +89,9 @@
|
||||
</where>
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
<select id="selectExamQuestionAnswerIdByQuId" resultType="java.lang.String">
|
||||
select answer_id from exam_question_answer where qu_id =#{quId}
|
||||
</select>
|
||||
<insert id="insertExamQuestionAnswerList">
|
||||
insert into exam_question_answer
|
||||
(answer_id, qu_id, is_right, image, content,contentIn,score_rate,sort)
|
||||
|
@@ -115,6 +115,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
FROM system_tenant
|
||||
WHERE deleted = 0
|
||||
</select>
|
||||
<select id="selectTenantId" resultType="java.lang.Long">
|
||||
select tenant_id from system_users limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertExamQuestion" parameterType="ExamQuestion">
|
||||
|
@@ -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.monitor.MonitorMapper">
|
||||
|
||||
<select id="selectByStuIdAndTaskIdTop" resultType="java.lang.String">
|
||||
select score from exam_monitor where stu_id =#{stuId} and task_id=#{taskId} ORDER BY score DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectByStuIdAndTaskIdNew" resultType="java.lang.String">
|
||||
select score from exam_monitor where stu_id =#{stuId} and task_id=#{taskId} ORDER BY create_time DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
@@ -0,0 +1,12 @@
|
||||
<?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.mysqlkeyword.MysqlKeywordMapper">
|
||||
|
||||
|
||||
<delete id="deleteByAnswerId">
|
||||
delete from exam_mysql_keyword where answer_id=#{answerId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@@ -13,14 +13,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="status" column="status" />
|
||||
<result property="unite" column="unite" />
|
||||
<result property="treeNum" column="tree_num" />
|
||||
<result property="roles" column="roles" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectExamSpecialtyVo">
|
||||
select sp_id, parent_id, ancestors, sp_name, order_num, status, creator, create_time, updater, update_time, unite, tree_num, tenant_id from exam_specialty
|
||||
select sp_id, parent_id, ancestors, sp_name, order_num, status, creator, create_time, updater, update_time, unite, tree_num, roles,tenant_id from exam_specialty
|
||||
</sql>
|
||||
|
||||
<select id="selectExamSpecialtyListVo" resultType="pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo">
|
||||
select sp_id as id, sp_name as name, parent_id, status, create_time from exam_specialty
|
||||
select sp_id as id, sp_name as name, parent_id, status, create_time,roles from exam_specialty
|
||||
<where>
|
||||
<if test="name != null and name != ''"> and sp_name like concat('%', #{name}, '%')</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
@@ -90,6 +91,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectExamSpecialtyVo"/>
|
||||
where sp_id = #{spId}
|
||||
</select>
|
||||
<select id="getRoleById" resultType="java.lang.String">
|
||||
select roles
|
||||
from exam_specialty where sp_id =#{id};
|
||||
</select>
|
||||
|
||||
<update id="deleteExamSpecialtyBySpId" parameterType="Long">
|
||||
update exam_specialty
|
||||
|
@@ -29,7 +29,8 @@ public class SecurityConfiguration {
|
||||
.requestMatchers("/swagger-ui/**").permitAll();
|
||||
// Spring Boot Actuator 的安全配置
|
||||
registry.requestMatchers("/actuator").permitAll()
|
||||
.requestMatchers("/actuator/**").permitAll();
|
||||
.requestMatchers("/actuator/**").permitAll()
|
||||
.requestMatchers("/admin-api/test/test").permitAll();
|
||||
// Druid 监控
|
||||
registry.requestMatchers("/druid/**").permitAll();
|
||||
// Spring Boot Admin Server 的安全配置
|
||||
|
@@ -0,0 +1,67 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.getpoints;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
import pc.exam.pp.module.judgement.controller.admin.getpoints.vo.Points;
|
||||
import pc.exam.pp.module.judgement.controller.admin.getpoints.vo.PointsVo;
|
||||
import pc.exam.pp.module.judgement.controller.service.getpoints.ExamGetPointsService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/exam/getPoints")
|
||||
public class GetPointsController {
|
||||
|
||||
@Autowired
|
||||
private ExamGetPointsService examGetPointsService;
|
||||
|
||||
/**
|
||||
* 得出文件操作考点
|
||||
* @return 得分
|
||||
*/
|
||||
@PostMapping("/get_filePoint")
|
||||
public CommonResult get_file_point(@RequestBody PointsVo pointsVo) throws IOException {
|
||||
return CommonResult.success(examGetPointsService.get_file_point(pointsVo));
|
||||
}
|
||||
/**
|
||||
* 得出MYSQL操作考点
|
||||
* @return 得分
|
||||
*/
|
||||
@PostMapping("/get_mysql_point")
|
||||
public CommonResult get_mysql_point(@RequestBody PointsVo pointsVo) throws IOException {
|
||||
return CommonResult.success(examGetPointsService.get_mysql_point(pointsVo));
|
||||
}
|
||||
/**
|
||||
* 新增MYSQL操作考点
|
||||
* @return 得分
|
||||
*/
|
||||
@PostMapping("/set_mysql_point")
|
||||
public CommonResult set_mysql_point(@RequestBody Points points) {
|
||||
return CommonResult.success(examGetPointsService.set_mysql_point(points));
|
||||
}
|
||||
/**
|
||||
* 更新MYSQL操作考点
|
||||
* @return 得分
|
||||
*/
|
||||
@PostMapping("/update_mysql_point")
|
||||
public CommonResult update_mysql_point(@RequestBody Points points) {
|
||||
return CommonResult.success(examGetPointsService.update_mysql_point(points));
|
||||
}
|
||||
|
||||
@GetMapping("/get_Point_id/{quId}")
|
||||
public CommonResult getPointById(@PathVariable("quId") String quId) {
|
||||
return CommonResult.success(examGetPointsService.getPointById(quId));
|
||||
}
|
||||
/**
|
||||
* 得出浏览器操作考点
|
||||
* @return 得分
|
||||
*/
|
||||
@PostMapping("/get_browser_point")
|
||||
//todo 老师自己设置,不读文件
|
||||
public CommonResult get_browser_point(@RequestBody List<ExamQuestionAnswer> examQuestionAnswers) throws IOException {
|
||||
return CommonResult.success(examGetPointsService.get_browser_point());
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.getpoints.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Points {
|
||||
private String quId;
|
||||
private List<ExamQuestionAnswer> questionAnswerList;
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.getpoints.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PointsVo {
|
||||
private String shucaiPath;
|
||||
private String answerPath;
|
||||
|
||||
}
|
@@ -1,8 +1,10 @@
|
||||
package pc.exam.pp.module.judgement.controller.service.browser;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
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.exam.dal.mysql.question.ExamQuestionAnswerMapper;
|
||||
import pc.exam.pp.module.judgement.controller.utils.brower.BookmarkChecker;
|
||||
import pc.exam.pp.module.judgement.controller.utils.brower.BookmarkDeleter;
|
||||
import pc.exam.pp.module.exam.utils.file.GetDifferencesBetweenFolders;
|
||||
@@ -15,10 +17,13 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class BrowserServericeImpl implements IBrowserServerice {
|
||||
static String answerLogPath ; // 文件路径
|
||||
@Resource
|
||||
private ExamQuestionAnswerMapper examQuestionAnswerMapper;
|
||||
//考生试题文件夹
|
||||
// static final String BASE_DIR = "D:/exam/4/";
|
||||
//谷歌浏览器
|
||||
@@ -31,16 +36,19 @@ public class BrowserServericeImpl implements IBrowserServerice {
|
||||
//Net得分点 文件类型 文件名 考点权值
|
||||
// 添加到文件夹 1
|
||||
// 添加到收藏夹 2
|
||||
List<ExamQuestionAnswer> answerList=new ArrayList<>();
|
||||
answerList.add(new ExamQuestionAnswer("","","","","1", "人民大学", "1", "1"));
|
||||
answerList.add(new ExamQuestionAnswer("","","","","1", "校情", "1", "2"));
|
||||
answerList.add(new ExamQuestionAnswer("","","","","1", "机构", "1", "3"));
|
||||
// List<ExamQuestionAnswer> answerList=new ArrayList<>();
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","人民大学", "添加到文件夹 ", "1", "1"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","校情", "添加到文件夹", "1", "2"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","机构", "添加到文件夹", "1", "3"));
|
||||
|
||||
List<ExamQuestionAnswer> answerList = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(question.getQuId());
|
||||
|
||||
//判断如果类型为1,为添加到文件夹的html,后缀加 .html
|
||||
for (ExamQuestionAnswer answer : answerList) {
|
||||
if ("1".equals(answer.getContent())) {
|
||||
String fileName = answer.getContentIn();
|
||||
if ("添加到文件夹".equals(answer.getContentIn())) {
|
||||
String fileName = answer.getContent();
|
||||
if (!fileName.endsWith(".html")) {
|
||||
answer.setContentIn(fileName + ".html");
|
||||
answer.setContent(fileName + ".html");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,16 +78,20 @@ public class BrowserServericeImpl implements IBrowserServerice {
|
||||
for (ExamQuestionAnswer examQuestionAnswer : answerList) {
|
||||
int currentScore = Integer.parseInt(examQuestionAnswer.getScoreRate()); // 当前得分
|
||||
|
||||
if ( examQuestionAnswer.getContent().equals("2")){
|
||||
String bookmarkNameToDelete = examQuestionAnswer.getContentIn();
|
||||
if ( "添加到收藏夹".equals(examQuestionAnswer.getContentIn())){
|
||||
String bookmarkNameToDelete = examQuestionAnswer.getContent();
|
||||
//检查收藏夹是否有书签
|
||||
if (BookmarkChecker.bookmarkExists(chromeBookmarkPath, bookmarkNameToDelete)) {
|
||||
//如果有 +权值
|
||||
boolean isCorrect = BookmarkChecker.bookmarkExists(chromeBookmarkPath, bookmarkNameToDelete);
|
||||
if (isCorrect) {
|
||||
//如果有 +权值
|
||||
studentScore += currentScore;
|
||||
System.out.println("📌 发现书签,准备删除...");
|
||||
appendToFile(answerLogPath,"考点"+bookmarkNameToDelete + " -> 得分权值:" + currentScore+"-> 是否得分:"+isCorrect+"✅");
|
||||
//删除此书签
|
||||
BookmarkDeleter.deleteBookmarkByName(chromeBookmarkPath, bookmarkNameToDelete);
|
||||
}
|
||||
else {
|
||||
appendToFile(answerLogPath,"考点"+bookmarkNameToDelete + " -> 得分权值:" + currentScore+"-> 是否得分:"+isCorrect+"❌");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,7 +112,8 @@ public class BrowserServericeImpl implements IBrowserServerice {
|
||||
static Integer compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles) {
|
||||
int totalScore = 0; // 记录总得分
|
||||
for (ExamQuestionAnswer answer : answerList) {
|
||||
String filePath = answer.getContentIn(); // 试题文件路径
|
||||
if ("添加到文件夹".equals(answer.getContentIn())) {
|
||||
String filePath = answer.getContent(); // 试题文件路径
|
||||
int currentScore = Integer.parseInt(answer.getScoreRate()); // 当前得分
|
||||
boolean isCorrect = false;
|
||||
// 如果学生提交中存在该文件,则得分
|
||||
@@ -109,12 +122,13 @@ public class BrowserServericeImpl implements IBrowserServerice {
|
||||
if (isCorrect) {
|
||||
totalScore += currentScore;
|
||||
|
||||
appendToFile(answerLogPath,"考点"+answer.getContentIn() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"✅");
|
||||
appendToFile(answerLogPath,"考点"+answer.getContent() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"✅");
|
||||
}else {
|
||||
|
||||
appendToFile(answerLogPath,"考点"+answer.getContentIn() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"❌");
|
||||
appendToFile(answerLogPath,"考点"+answer.getContent() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"❌");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//返回累加的得分点
|
||||
return totalScore;
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package pc.exam.pp.module.judgement.controller.service.file;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
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.exam.dal.mysql.question.ExamQuestionAnswerMapper;
|
||||
import pc.exam.pp.module.exam.utils.file.GetDifferencesBetweenFolders;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
@@ -18,20 +20,22 @@ import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class FileServericeImpl implements IFileServerice {
|
||||
static final String BASE_DIR = "D:/exam/3/";
|
||||
static String answerLogPath ; // 文件路径
|
||||
|
||||
@Resource
|
||||
private ExamQuestionAnswerMapper examQuestionAnswerMapper;
|
||||
@Override
|
||||
public double run_file_point(double score,File file, ExamQuestion question) throws IOException {
|
||||
//todo 得到学生的考题答案
|
||||
List<ExamQuestionAnswer> answerList=new ArrayList<>();
|
||||
answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\RLQM.MEM", "考察删除", "1", "1"));
|
||||
answerList.add(new ExamQuestionAnswer("","","","","TING\\XYU\\AUTOE.BAT", "考察删除", "1", "2"));
|
||||
answerList.add(new ExamQuestionAnswer("","","","","AHEWL\\KMENS", "考察名称", "1", "3"));
|
||||
answerList.add(new ExamQuestionAnswer("","","","","EDZK\\RONGHE.COM", "考察名称", "1", "4"));
|
||||
answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\PLAY.MEM", "考察名称", "1", "5"));
|
||||
|
||||
answerList.add(new ExamQuestionAnswer("","","","","WUE\\PB6.txt", "考察名称", "1", "6"));
|
||||
List<ExamQuestionAnswer> answerList = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(question.getQuId());
|
||||
|
||||
//todo 得到学生的考题答案
|
||||
// List<ExamQuestionAnswer> answerList=new ArrayList<>();
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\RLQM.MEM", "考察删除", "1", "1"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","TING\\XYU\\AUTOE.BAT", "考察删除", "1", "2"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","AHEWL\\KMENS", "考察名称", "1", "3"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","EDZK\\RONGHE.COM", "考察名称", "1", "4"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\PLAY.MEM", "考察名称", "1", "5"));
|
||||
// answerList.add(new ExamQuestionAnswer("","","","","WUE\\PB6.txt", "考察名称", "1", "6"));
|
||||
|
||||
|
||||
File stuPath = file;
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package pc.exam.pp.module.judgement.controller.service.getpoints;
|
||||
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
import pc.exam.pp.module.judgement.controller.admin.getpoints.vo.Points;
|
||||
import pc.exam.pp.module.judgement.controller.admin.getpoints.vo.PointsVo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface ExamGetPointsService {
|
||||
|
||||
|
||||
|
||||
List<ExamQuestionAnswer> get_file_point(PointsVo pointsVo) throws IOException;
|
||||
|
||||
List<String> get_mysql_point(PointsVo pointsVo) throws IOException;
|
||||
|
||||
List<ExamQuestionAnswer> get_browser_point();
|
||||
|
||||
boolean set_mysql_point(Points points);
|
||||
|
||||
boolean update_mysql_point(Points points);
|
||||
|
||||
List<ExamQuestionAnswer> getPointById(String quId);
|
||||
}
|
@@ -0,0 +1,274 @@
|
||||
package pc.exam.pp.module.judgement.controller.service.getpoints;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamMysqlKeyword;
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
import pc.exam.pp.module.exam.dal.mysql.mysqlkeyword.MysqlKeywordMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionAnswerMapper;
|
||||
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
|
||||
import pc.exam.pp.module.exam.utils.file.GetDifferencesBetweenFolders;
|
||||
import pc.exam.pp.module.exam.utils.uuid.IdUtils;
|
||||
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.controller.admin.getpoints.vo.Points;
|
||||
import pc.exam.pp.module.judgement.controller.admin.getpoints.vo.PointsVo;
|
||||
import pc.exam.pp.module.judgement.controller.utils.zip.ZipUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.MalformedInputException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ExamGetPointsServiceImpl implements ExamGetPointsService{
|
||||
@Resource
|
||||
ConfigService configService;
|
||||
|
||||
@Resource
|
||||
MysqlKeywordMapper mysqlKeywordMapper;
|
||||
@Resource
|
||||
private ExamQuestionAnswerMapper examQuestionAnswerMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<ExamQuestionAnswer> get_file_point(PointsVo pointsVo) throws IOException {
|
||||
|
||||
// 获取平台文件参数
|
||||
ConfigDO config = configService.getConfigByKey("file_down_path");
|
||||
|
||||
String sthPath = ZipUtil.downloadStudentFile(pointsVo.getShucaiPath(), config.getValue());
|
||||
String answerPath = ZipUtil.downloadStudentFile(pointsVo.getAnswerPath(), config.getValue());
|
||||
File zip_file_sth = new File(sthPath);
|
||||
File zip_file_answer= new File(answerPath);
|
||||
|
||||
//获取到得是zip文件,需要解压
|
||||
String stuFilePath = ZipUtil.unzipToNamedFolder(sthPath);
|
||||
String answerFilePath = ZipUtil.unzipToNamedFolder(answerPath);
|
||||
|
||||
//解压之后得文件获取文件夹和文件
|
||||
File folderStu = new File(stuFilePath);
|
||||
|
||||
File folderAnswer = new File(stuFilePath);
|
||||
|
||||
|
||||
|
||||
|
||||
List<ExamQuestionAnswer> answerList = new ArrayList<>();
|
||||
AtomicInteger sortCounter = new AtomicInteger(1); // 计数器
|
||||
|
||||
// 获取 shucai 和 win 文件夹的差异
|
||||
Map<String, String> differences = GetDifferencesBetweenFolders.getDifferencesBetweenFolders(stuFilePath, answerFilePath);
|
||||
|
||||
List<ExamQuestionAnswer> formattedDifferences = differences.entrySet().stream()
|
||||
.map(entry -> {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
ExamQuestionAnswer answer = new ExamQuestionAnswer();
|
||||
answer.setContent(key); // 设置文件路径
|
||||
answer.setScoreRate("1");
|
||||
//这里设置answer的排序,按照循环次数来
|
||||
answer.setSort(String.valueOf(sortCounter.getAndIncrement())); // 按顺序设置排序值
|
||||
if (value.startsWith("仅存在于 "+stuFilePath)) {
|
||||
answer.setContentIn("考察删除");
|
||||
} else if (value.startsWith("仅存在于 "+answerFilePath)) {
|
||||
answer.setContentIn("考察名称");
|
||||
} else if (value.startsWith("属性不同")) {
|
||||
answer.setContentIn("考察属性");
|
||||
// answer.setContent(key + " -> " + value.split(" vs ")[1]); // 设置属性信息
|
||||
}
|
||||
return answer;
|
||||
})
|
||||
.sorted(Comparator.comparingInt(answer -> Integer.parseInt(answer.getSort()))) // 按 sort 排序
|
||||
.collect(Collectors.toList());
|
||||
answerList.addAll(formattedDifferences);
|
||||
// zip_file_sth.delete();
|
||||
// zip_file_answer.delete();
|
||||
// folderStu.delete();
|
||||
// folderAnswer.delete();
|
||||
|
||||
return answerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> get_mysql_point(PointsVo pointsVo) throws IOException {
|
||||
|
||||
String answerPath = pointsVo.getAnswerPath();
|
||||
// 获取平台文件参数
|
||||
ConfigDO config = configService.getConfigByKey("file_down_path");
|
||||
|
||||
String sthPath = ZipUtil.downloadStudentFile(pointsVo.getAnswerPath(), config.getValue());
|
||||
System.out.println(sthPath);
|
||||
List<String> sqlStatements = readSQLFromFile(sthPath);
|
||||
return sqlStatements;
|
||||
}
|
||||
private static List<String> readSQLFromFile(String filePath) throws IOException {
|
||||
|
||||
|
||||
List<String> lines = readFileAutoCharset(filePath);
|
||||
List<String> sqlList = parseSql(lines);
|
||||
|
||||
for (String sql : sqlList) {
|
||||
System.out.println(sql);
|
||||
System.out.println("-------");
|
||||
}
|
||||
|
||||
return sqlList;
|
||||
}
|
||||
|
||||
// 自动识别 UTF-8 or GBK
|
||||
private static List<String> readFileAutoCharset(String filePath) throws IOException {
|
||||
try {
|
||||
// 优先尝试 UTF-8
|
||||
return Files.readAllLines(Paths.get(filePath), Charset.forName("UTF-8"));
|
||||
} catch (MalformedInputException e) {
|
||||
// 如果UTF-8失败,再尝试GBK
|
||||
System.out.println("文件不是UTF-8编码,尝试使用GBK编码读取...");
|
||||
return Files.readAllLines(Paths.get(filePath), Charset.forName("GBK"));
|
||||
}
|
||||
}
|
||||
// 解析SQL:去掉注释,只保留SQL语句
|
||||
private static List<String> parseSql(List<String> lines) {
|
||||
List<String> sqlList = new ArrayList<>();
|
||||
StringBuilder currentSql = new StringBuilder();
|
||||
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("--")) {
|
||||
// 遇到新的注释(比如 -- 1.),先把之前的SQL收进去
|
||||
if (currentSql.length() > 0) {
|
||||
sqlList.add(currentSql.toString().trim());
|
||||
currentSql.setLength(0);
|
||||
}
|
||||
continue; // 注释行不用管
|
||||
}
|
||||
|
||||
// 累加 SQL 内容
|
||||
currentSql.append(line).append("\n");
|
||||
}
|
||||
|
||||
if (currentSql.length() > 0) {
|
||||
sqlList.add(currentSql.toString().trim());
|
||||
}
|
||||
|
||||
return sqlList;
|
||||
}
|
||||
@Override
|
||||
public List<ExamQuestionAnswer> get_browser_point() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set_mysql_point(Points points) {
|
||||
try {
|
||||
List<ExamQuestionAnswer> questionAnswerList = points.getQuestionAnswerList();
|
||||
if (CollectionUtils.isEmpty(questionAnswerList)) {
|
||||
return true;
|
||||
}
|
||||
List<ExamMysqlKeyword> allKeywords = new ArrayList<>();
|
||||
|
||||
for (ExamQuestionAnswer examQuestionAnswer : questionAnswerList) {
|
||||
String answerId = IdUtils.simpleUUID();
|
||||
examQuestionAnswer.setAnswerId(answerId);
|
||||
examQuestionAnswer.setQuId(points.getQuId());
|
||||
List<ExamMysqlKeyword> keywordList = examQuestionAnswer.getExamMysqlKeywordList();
|
||||
if (!CollectionUtils.isEmpty(keywordList)) {
|
||||
for (ExamMysqlKeyword keyword : keywordList) {
|
||||
keyword.setAnswerId(answerId);
|
||||
keyword.setKeywordId(IdUtils.simpleUUID());
|
||||
}
|
||||
allKeywords.addAll(keywordList);
|
||||
}
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(allKeywords)) {
|
||||
mysqlKeywordMapper.insertOrUpdate(allKeywords);
|
||||
}
|
||||
|
||||
examQuestionAnswerMapper.insertOrUpdate(questionAnswerList);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("保存考试点信息失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update_mysql_point(Points points) {
|
||||
try {
|
||||
String quId = points.getQuId();
|
||||
List<ExamQuestionAnswer> questionAnswerList = points.getQuestionAnswerList();
|
||||
// 查询旧 answerId
|
||||
List<String> oldAnswerIds = examQuestionAnswerMapper.selectExamQuestionAnswerIdByQuId(quId);
|
||||
|
||||
// 删除旧关键字
|
||||
if (!CollectionUtils.isEmpty(oldAnswerIds)) {
|
||||
for (String aid : oldAnswerIds) {
|
||||
mysqlKeywordMapper.deleteByAnswerId(aid);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除旧答案
|
||||
examQuestionAnswerMapper.deleteExamQuestionAnswerByQuesId(quId);
|
||||
|
||||
// 如果没有新数据就返回
|
||||
if (CollectionUtils.isEmpty(questionAnswerList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 新的 keyword 收集
|
||||
List<ExamMysqlKeyword> newKeywordList = new ArrayList<>();
|
||||
for (ExamQuestionAnswer answer : questionAnswerList) {
|
||||
String answerId = IdUtils.simpleUUID();
|
||||
answer.setAnswerId(answerId);
|
||||
answer.setQuId(quId); // 以防前端未传
|
||||
|
||||
List<ExamMysqlKeyword> keywordList = answer.getExamMysqlKeywordList();
|
||||
if (!CollectionUtils.isEmpty(keywordList)) {
|
||||
for (ExamMysqlKeyword keyword : keywordList) {
|
||||
keyword.setAnswerId(answerId);
|
||||
keyword.setKeywordId(IdUtils.simpleUUID());
|
||||
}
|
||||
newKeywordList.addAll(keywordList);
|
||||
}
|
||||
}
|
||||
|
||||
// 插入新答案和关键词
|
||||
examQuestionAnswerMapper.insertOrUpdate(questionAnswerList);
|
||||
if (!CollectionUtils.isEmpty(newKeywordList)) {
|
||||
mysqlKeywordMapper.insertOrUpdate(newKeywordList);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("更新考试点信息失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExamQuestionAnswer> getPointById(String quId) {
|
||||
List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(quId);
|
||||
if (!CollectionUtils.isEmpty(examQuestionAnswers)) {
|
||||
for (ExamQuestionAnswer examQuestionAnswer : examQuestionAnswers) {
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> newKeywordList = mysqlKeywordMapper.selectList(
|
||||
new QueryWrapper<ExamMysqlKeyword>().eq("answer_id", answerId)
|
||||
);
|
||||
examQuestionAnswer.setExamMysqlKeywordList(newKeywordList);
|
||||
}
|
||||
}
|
||||
return examQuestionAnswers;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
package pc.exam.pp.module.judgement.controller.utils.zip;
|
||||
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.DosFileAttributeView;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class ZipUtil {
|
||||
|
||||
public static String unzipToNamedFolder(String zipFilePath) {
|
||||
File zipFile = new File(zipFilePath);
|
||||
|
||||
if (!zipFile.exists() || !zipFile.getName().toLowerCase().endsWith(".zip")) {
|
||||
System.err.println("❌ 无效 zip 文件: " + zipFilePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
String fileNameNoExt = zipFile.getName().replaceAll("(?i)\\.zip$", "");
|
||||
File extractDir = new File(zipFile.getParentFile(), fileNameNoExt);
|
||||
if (!extractDir.exists()) extractDir.mkdirs();
|
||||
|
||||
// 指定编码(GBK 用于支持中文文件名,UTF-8 用于通用 ZIP)
|
||||
try (ZipFile zf = new ZipFile(zipFile, "GBK")) {
|
||||
Enumeration<ZipArchiveEntry> entries = zf.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipArchiveEntry entry = entries.nextElement();
|
||||
File outFile = new File(extractDir, entry.getName());
|
||||
|
||||
// 防止 Zip 穿越攻击
|
||||
if (!outFile.getCanonicalPath().startsWith(extractDir.getCanonicalPath())) {
|
||||
throw new IOException("非法路径: " + entry.getName());
|
||||
}
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
outFile.mkdirs();
|
||||
} else {
|
||||
File parent = outFile.getParentFile();
|
||||
if (!parent.exists()) parent.mkdirs();
|
||||
|
||||
try (InputStream is = zf.getInputStream(entry);
|
||||
OutputStream os = new FileOutputStream(outFile)) {
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) > 0) {
|
||||
os.write(buffer, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 读取 Zip 中的外部文件属性(低16位,DOS属性)
|
||||
int externalAttrs = (int) (entry.getExternalAttributes() & 0xFFFF);
|
||||
|
||||
// DOS隐藏属性是第二位(0x02)
|
||||
boolean hidden = (externalAttrs & 0x02) != 0;
|
||||
// DOS只读属性是第一位(0x01)
|
||||
boolean readOnly = (externalAttrs & 0x01) != 0;
|
||||
|
||||
Path outPath = outFile.toPath();
|
||||
DosFileAttributeView view = Files.getFileAttributeView(outPath, DosFileAttributeView.class);
|
||||
|
||||
if (view != null) {
|
||||
try {
|
||||
// 设置隐藏属性
|
||||
view.setHidden(hidden);
|
||||
// 设置只读属性,需要用Files.setAttribute
|
||||
Files.setAttribute(outPath, "dos:readonly", readOnly);
|
||||
} catch (IOException e) {
|
||||
System.err.println("设置文件属性失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("✅ 解压完成,目录:" + extractDir.getAbsolutePath());
|
||||
return extractDir.getAbsolutePath();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("❌ 解压失败: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String downloadStudentFile(String fileUrl, String filePath) {
|
||||
try {
|
||||
URL url = new URL(fileUrl);
|
||||
URLConnection connection = url.openConnection();
|
||||
|
||||
String fileName = new File(url.getPath()).getName();
|
||||
File dir = new File(filePath);
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
|
||||
File saveFile = new File(dir, fileName);
|
||||
|
||||
try (InputStream in = connection.getInputStream();
|
||||
FileOutputStream out = new FileOutputStream(saveFile)) {
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath());
|
||||
return saveFile.getAbsolutePath();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("❌ 下载失败: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ spring:
|
||||
time-to-live: 1h # 设置过期时间为 1 小时
|
||||
|
||||
server:
|
||||
role: center
|
||||
servlet:
|
||||
encoding:
|
||||
enabled: true
|
||||
|
Reference in New Issue
Block a user