|
|
|
@ -1,110 +1,122 @@
|
|
|
|
|
//package com.sztzjy.money_management.controller;
|
|
|
|
|
//
|
|
|
|
|
//import cn.hutool.core.util.IdUtil;
|
|
|
|
|
//import com.sztzjy.money_management.annotation.AnonymousAccess;
|
|
|
|
|
//import com.sztzjy.money_management.entity.StuTrainingWithBLOBs;
|
|
|
|
|
//import com.sztzjy.money_management.entity.TrainingReportExample;
|
|
|
|
|
//import com.sztzjy.money_management.util.ResultEntity;
|
|
|
|
|
//import io.swagger.annotations.Api;
|
|
|
|
|
//import io.swagger.annotations.ApiOperation;
|
|
|
|
|
//import io.swagger.annotations.ApiParam;
|
|
|
|
|
//import org.springframework.http.HttpStatus;
|
|
|
|
|
//import org.springframework.util.Assert;
|
|
|
|
|
//import org.springframework.web.bind.annotation.*;
|
|
|
|
|
//import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
//
|
|
|
|
|
//import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
//import java.math.BigDecimal;
|
|
|
|
|
//import java.util.Date;
|
|
|
|
|
//import java.util.List;
|
|
|
|
|
//
|
|
|
|
|
//@RestController
|
|
|
|
|
//@Api(tags = "实验报告相关")
|
|
|
|
|
//@RequestMapping("api/ResourceController")
|
|
|
|
|
//public class TrainingReport {
|
|
|
|
|
// @AnonymousAccess
|
|
|
|
|
// @ApiOperation("实验报告展示")
|
|
|
|
|
// @PostMapping("getReportByUserId")
|
|
|
|
|
// public ResultEntity<List<TrainingReport>> getReportByUserId(@RequestParam String userId,
|
|
|
|
|
// @RequestParam String systemOwner) {
|
|
|
|
|
// TrainingReportExample trainingReportExample = new TrainingReportExample();
|
|
|
|
|
// trainingReportExample.createCriteria().andUserIdEqualTo(userId).andSystemOwnerEqualTo(systemOwner);
|
|
|
|
|
// List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample);
|
|
|
|
|
// return new ResultEntity<>(trainingReports);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @AnonymousAccess
|
|
|
|
|
// @PostMapping("uploadReport")
|
|
|
|
|
// @ApiOperation("上传报告")
|
|
|
|
|
// public ResultEntity<String> uploadReport(@RequestPart(name = "file") MultipartFile file,
|
|
|
|
|
// @ApiParam("文件名称") @RequestParam String fileName,
|
|
|
|
|
// @RequestParam String userId,
|
|
|
|
|
// @RequestParam String trainingId,
|
|
|
|
|
// @ApiParam("章节ID") @RequestParam String chapterId,
|
|
|
|
|
// @ApiParam("章节名称") @RequestParam String chapterName,
|
|
|
|
|
// @RequestParam String schoolId,
|
|
|
|
|
// @RequestParam String systemOwner) {
|
|
|
|
|
// int size = (int) file.getSize() / (1024 * 1024); //拿到MB为单位的大小
|
|
|
|
|
// String originalFilename = file.getOriginalFilename();
|
|
|
|
|
// assert originalFilename != null;
|
|
|
|
|
// String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
|
|
|
|
|
// if (!fileExtension.equals(".pdf") && !fileExtension.equals(".doc") && !fileExtension.equals(".docx")) {
|
|
|
|
|
// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件必须为word或pdf!");
|
|
|
|
|
// }
|
|
|
|
|
// //老师评分后不允许上传
|
|
|
|
|
// TrainingReportExample example = new TrainingReportExample();
|
|
|
|
|
// example.createCriteria().andSchoolIdEqualTo(schoolId).andUserIdEqualTo(userId).andChapterIdEqualTo(chapterId).andSystemOwnerEqualTo(systemOwner);
|
|
|
|
|
// List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
// if (!trainingReports.isEmpty()) { //上传过
|
|
|
|
|
// TrainingReport trainingReport = trainingReports.get(0);
|
|
|
|
|
// BigDecimal teacherScore = trainingReport.getTeacherScore();
|
|
|
|
|
// if (teacherScore != null) { //老师评分过
|
|
|
|
|
// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "老师已评分,无法重新上传!");
|
|
|
|
|
// } else { //老师没评分 多次上传 直接覆盖
|
|
|
|
|
// String filePath = fileUtil.upload(file);
|
|
|
|
|
// trainingReport.setFilePath(filePath);
|
|
|
|
|
// trainingReport.setUploadTime(new Date());
|
|
|
|
|
// trainingReport.setReportName(fileName);
|
|
|
|
|
// trainingReport.setReportSize(size);
|
|
|
|
|
// trainingReportMapper.updateByPrimaryKeyWithBLOBs(trainingReport);
|
|
|
|
|
// return new ResultEntity<>(HttpStatus.BAD_REQUEST, "重新上传成功!");
|
|
|
|
|
// }
|
|
|
|
|
// } else { //第一次上传
|
|
|
|
|
// String filePath = fileUtil.upload(file);
|
|
|
|
|
// TrainingReport trainingReport = new TrainingReport();
|
|
|
|
|
// trainingReport.setReportId(IdUtil.randomUUID());
|
|
|
|
|
// trainingReport.setFilePath(filePath);
|
|
|
|
|
// trainingReport.setUploadTime(new Date());
|
|
|
|
|
// trainingReport.setReportName(fileName);
|
|
|
|
|
// trainingReport.setChapterId(chapterId);
|
|
|
|
|
// trainingReport.setChapterName(chapterName);
|
|
|
|
|
// trainingReport.setUserId(userId);
|
|
|
|
|
// trainingReport.setSchoolId(schoolId);
|
|
|
|
|
// trainingReport.setReportSize(size);
|
|
|
|
|
// trainingReport.setSystemOwner(systemOwner);
|
|
|
|
|
// StuTrainingWithBLOBs stuTrainingWithBLOBs = stuTrainingMapper.selectByPrimaryKey(trainingId);
|
|
|
|
|
// stuTrainingWithBLOBs.setReportId(trainingReport.getReportId()); // 第一次上传时设置实训表的报告ID
|
|
|
|
|
// trainingReportMapper.insert(trainingReport);
|
|
|
|
|
// return new ResultEntity<>(HttpStatus.OK, "上传成功!");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @AnonymousAccess
|
|
|
|
|
// @ApiOperation("实验报告下载")
|
|
|
|
|
// @GetMapping("downloadReport")
|
|
|
|
|
// public void downloadReport(@RequestParam String reportId, HttpServletResponse response) {
|
|
|
|
|
// TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(reportId);
|
|
|
|
|
// Assert.isTrue(trainingReport != null && trainingReport.getFilePath() != null, "报告不存在");
|
|
|
|
|
// fileUtil.download(response, trainingReport.getReportName(), trainingReport.getFilePath());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// @AnonymousAccess
|
|
|
|
|
// @ApiOperation("实验报告查看评语")
|
|
|
|
|
// @PostMapping("getTeacherCommentById")
|
|
|
|
|
// public ResultEntity<String> getTeacherCommentById(@RequestParam String reportId) {
|
|
|
|
|
// TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(reportId);
|
|
|
|
|
// return new ResultEntity<>(trainingReport.getTeacherComment());
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
package com.sztzjy.money_management.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.sztzjy.money_management.annotation.AnonymousAccess;
|
|
|
|
|
import com.sztzjy.money_management.entity.StuTrainingWithBLOBs;
|
|
|
|
|
import com.sztzjy.money_management.entity.TrainingReport;
|
|
|
|
|
import com.sztzjy.money_management.entity.TrainingReportExample;
|
|
|
|
|
import com.sztzjy.money_management.mapper.StuTrainingMapper;
|
|
|
|
|
import com.sztzjy.money_management.mapper.TrainingReportMapper;
|
|
|
|
|
import com.sztzjy.money_management.util.ResultEntity;
|
|
|
|
|
import com.sztzjy.money_management.util.file.IFileUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@Api(tags = "实验报告相关")
|
|
|
|
|
@RequestMapping("api/TrainingReportController")
|
|
|
|
|
public class TrainingReportController {
|
|
|
|
|
@Autowired
|
|
|
|
|
TrainingReportMapper trainingReportMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFileUtil fileUtil;
|
|
|
|
|
@Value("${file.path}")
|
|
|
|
|
private String filePath;
|
|
|
|
|
@Autowired
|
|
|
|
|
StuTrainingMapper trainingMapper;
|
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@ApiOperation("学习成绩实验报告展示")
|
|
|
|
|
@PostMapping("getReportByUserId")
|
|
|
|
|
public ResultEntity<List<TrainingReport>> getReportByUserId(@RequestParam String userId,@RequestParam String chapterId) {
|
|
|
|
|
TrainingReportExample trainingReportExample = new TrainingReportExample();
|
|
|
|
|
trainingReportExample.createCriteria().andUserIdEqualTo(userId).andChapterIdEqualTo(chapterId);
|
|
|
|
|
List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample);
|
|
|
|
|
return new ResultEntity<>(trainingReports);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("uploadReport")
|
|
|
|
|
@ApiOperation("上传报告")
|
|
|
|
|
public ResultEntity<String> uploadReport(@RequestPart(name = "file") MultipartFile file,
|
|
|
|
|
@ApiParam("文件名称") @RequestParam String fileName,
|
|
|
|
|
@RequestParam String userId,
|
|
|
|
|
@RequestParam String trainingId,
|
|
|
|
|
@ApiParam("章节ID") @RequestParam String chapterId,
|
|
|
|
|
@ApiParam("章节名称") @RequestParam String chapterName,
|
|
|
|
|
@RequestParam String schoolId) {
|
|
|
|
|
int size = (int) file.getSize() / (1024 * 1024); //拿到MB为单位的大小
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
|
|
assert originalFilename != null;
|
|
|
|
|
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
|
|
|
|
|
if (!fileExtension.equals(".pdf") && !fileExtension.equals(".doc") && !fileExtension.equals(".docx")) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件必须为pdf!");
|
|
|
|
|
}
|
|
|
|
|
//老师评分后不允许上传
|
|
|
|
|
TrainingReportExample example = new TrainingReportExample();
|
|
|
|
|
example.createCriteria().andSchoolIdEqualTo(schoolId).andUserIdEqualTo(userId).andChapterIdEqualTo(chapterId);
|
|
|
|
|
List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
if (!trainingReports.isEmpty()) { //上传过
|
|
|
|
|
TrainingReport trainingReport = trainingReports.get(0);
|
|
|
|
|
BigDecimal teacherScore = trainingReport.getTeacherScore();
|
|
|
|
|
if (teacherScore != null) { //老师评分过
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "老师已评分,无法重新上传!");
|
|
|
|
|
} else { //老师没评分 多次上传 直接覆盖
|
|
|
|
|
String filePath = fileUtil.upload(file);
|
|
|
|
|
trainingReport.setFilePath(filePath);
|
|
|
|
|
trainingReport.setUploadTime(new Date());
|
|
|
|
|
trainingReport.setReportName(fileName);
|
|
|
|
|
trainingReport.setReportSize(BigDecimal.valueOf(size));
|
|
|
|
|
trainingReportMapper.updateByPrimaryKeyWithBLOBs(trainingReport);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "重新上传成功!");
|
|
|
|
|
}
|
|
|
|
|
} else { //第一次上传
|
|
|
|
|
String filePath = fileUtil.upload(file);
|
|
|
|
|
TrainingReport trainingReport = new TrainingReport();
|
|
|
|
|
trainingReport.setReportId(IdUtil.randomUUID());
|
|
|
|
|
trainingReport.setFilePath(filePath);
|
|
|
|
|
trainingReport.setUploadTime(new Date());
|
|
|
|
|
trainingReport.setReportName(fileName);
|
|
|
|
|
trainingReport.setChapterId(chapterId);
|
|
|
|
|
trainingReport.setChapterName(chapterName);
|
|
|
|
|
trainingReport.setUserId(userId);
|
|
|
|
|
trainingReport.setSchoolId(schoolId);
|
|
|
|
|
trainingReport.setReportSize(BigDecimal.valueOf(size));
|
|
|
|
|
StuTrainingWithBLOBs stuTrainingWithBLOBs = trainingMapper.selectByPrimaryKey(trainingId);
|
|
|
|
|
stuTrainingWithBLOBs.setReportId(trainingReport.getReportId()); // 第一次上传时设置实训表的报告ID
|
|
|
|
|
trainingReportMapper.insert(trainingReport);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "上传成功!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@ApiOperation("实验报告下载")
|
|
|
|
|
@GetMapping("downloadReport")
|
|
|
|
|
public void downloadReport(@RequestParam String reportId, HttpServletResponse response) {
|
|
|
|
|
TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(reportId);
|
|
|
|
|
Assert.isTrue(trainingReport != null && trainingReport.getFilePath() != null, "报告不存在");
|
|
|
|
|
fileUtil.download(response, trainingReport.getReportName(), trainingReport.getFilePath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@ApiOperation("实验报告查看评语")
|
|
|
|
|
@PostMapping("getTeacherCommentById")
|
|
|
|
|
public ResultEntity<String> getTeacherCommentById(@RequestParam String reportId) {
|
|
|
|
|
TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(reportId);
|
|
|
|
|
return new ResultEntity<>(trainingReport.getTeacherComment());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|