|
|
|
|
@ -29,6 +29,8 @@ import com.sztzjy.linkCommerce.util.pdfUtils.PDFConvertUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
@ -51,6 +53,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
@RequestMapping("api/weight")
|
|
|
|
|
@RestController
|
|
|
|
|
public class TeaScoreController {
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(TeaScoreController.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
WeightMapper weightMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
@ -265,10 +269,16 @@ public class TeaScoreController {
|
|
|
|
|
public ResponseEntity<byte[]> previewTaskReferenceAnswer(@RequestParam String classId,
|
|
|
|
|
@RequestParam String taskId,
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
long startAt = System.currentTimeMillis();
|
|
|
|
|
JwtUser operator = currentUser(request);
|
|
|
|
|
try {
|
|
|
|
|
teacherScoreService.requireAccessibleClass(currentUser(request), classId);
|
|
|
|
|
teacherScoreService.requireAccessibleClass(operator, classId);
|
|
|
|
|
TrainingTask task = trainingTaskMapper.selectByPrimaryKey(taskId);
|
|
|
|
|
if (task == null) return ResponseEntity.notFound().build();
|
|
|
|
|
if (task == null) {
|
|
|
|
|
log.warn("参考答案预览失败:任务不存在 classId={} taskId={} userId={}", classId, taskId,
|
|
|
|
|
operator == null ? null : operator.getUserId());
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
TrainingTaskClassConfig classConfig = trainingTaskClassConfigMapper == null ? null
|
|
|
|
|
: trainingTaskClassConfigMapper.selectByTeachingClassAndTaskKey(classId, task.getTaskKey());
|
|
|
|
|
String referenceUrl = classConfig != null && StringUtils.isNotBlank(classConfig.getReferenceAnswerUrl())
|
|
|
|
|
@ -276,6 +286,8 @@ public class TeaScoreController {
|
|
|
|
|
String referenceName = classConfig != null && StringUtils.isNotBlank(classConfig.getReferenceAnswerName())
|
|
|
|
|
? classConfig.getReferenceAnswerName() : task == null ? null : task.getReferenceAnswerName();
|
|
|
|
|
if (StringUtils.isBlank(referenceUrl)) {
|
|
|
|
|
log.warn("参考答案预览失败:未配置参考答案 classId={} taskId={} taskKey={} userId={}",
|
|
|
|
|
classId, taskId, task.getTaskKey(), operator == null ? null : operator.getUserId());
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
String name = StringUtils.defaultIfBlank(referenceName, referenceUrl);
|
|
|
|
|
@ -283,19 +295,41 @@ public class TeaScoreController {
|
|
|
|
|
int slash = path.indexOf("/file/");
|
|
|
|
|
if (slash >= 0) path = path.substring(slash + 1);
|
|
|
|
|
File source = new File(fileUtil.getFullPath(path));
|
|
|
|
|
if (!source.exists() || !PDFConvertUtil.isCreatePdf(name)) return ResponseEntity.notFound().build();
|
|
|
|
|
if (!source.exists() || !PDFConvertUtil.isCreatePdf(name)) {
|
|
|
|
|
log.warn("参考答案预览失败:文件不存在或类型不支持转换 classId={} taskKey={} userId={} name={} url={} path={} exists={}",
|
|
|
|
|
classId, task.getTaskKey(), operator == null ? null : operator.getUserId(),
|
|
|
|
|
name, referenceUrl, source.getAbsolutePath(), source.exists());
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
|
try (InputStream input = Files.newInputStream(source.toPath())) {
|
|
|
|
|
if (!PDFConvertUtil.convertToPDFByFileNameSuffix(name, input, output)) return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).build();
|
|
|
|
|
}
|
|
|
|
|
if (!PDFConvertUtil.convertToPDFByFileNameSuffix(name, input, output)) {
|
|
|
|
|
log.warn("参考答案预览失败:文档转换未成功 classId={} taskKey={} userId={} name={} path={}",
|
|
|
|
|
classId, task.getTaskKey(), operator == null ? null : operator.getUserId(), name, source.getAbsolutePath());
|
|
|
|
|
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("参考答案预览成功 classId={} taskKey={} userId={} name={} pdfBytes={} elapsed={}ms",
|
|
|
|
|
classId, task.getTaskKey(), operator == null ? null : operator.getUserId(),
|
|
|
|
|
name, output.size(), System.currentTimeMillis() - startAt);
|
|
|
|
|
return ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).header("Content-Disposition", "inline; filename=reference-answer.pdf").body(output.toByteArray());
|
|
|
|
|
} catch (com.sztzjy.linkCommerce.config.exception.handler.ServiceException e) {
|
|
|
|
|
log.warn("参考答案预览失败:权限或参数校验未通过 classId={} taskId={} userId={} status={} reason={}",
|
|
|
|
|
classId, taskId, operator == null ? null : operator.getUserId(), e.getCode(), e.getMessage());
|
|
|
|
|
return ResponseEntity.status(e.getCode()).build();
|
|
|
|
|
} catch (RuntimeException | java.io.IOException e) {
|
|
|
|
|
log.warn("参考答案预览失败:转换异常 classId={} taskId={} userId={} name={}",
|
|
|
|
|
classId, taskId, operator == null ? null : operator.getUserId(),
|
|
|
|
|
StringUtils.defaultIfBlank(currentTaskKey(taskId), "-"), e);
|
|
|
|
|
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String currentTaskKey(String taskId) {
|
|
|
|
|
TrainingTask task = trainingTaskMapper == null ? null : trainingTaskMapper.selectByPrimaryKey(taskId);
|
|
|
|
|
return task == null ? null : task.getTaskKey();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/batchSaveTaskTeacherScore")
|
|
|
|
|
@ApiOperation("批量保存教师任务评分")
|
|
|
|
|
@Transactional
|
|
|
|
|
|