新增接口,修改BUG

master
xiaoCJ 2 years ago
parent 28e6e47dea
commit f96bc3c0f0

@ -28,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -131,21 +132,46 @@ public class TrainingScoreController {
//学生端实训报告提交 //学生端实训报告提交
@PostMapping("/submitReport") @PostMapping("/submitReport")
public AjaxResult submitReport(@RequestParam String content, public AjaxResult submitReport(@RequestBody JSONObject jsonObject) {
@RequestParam Long userId) { Long userId = jsonObject.getLong("userId");
String content = jsonObject.getString("content");
return trainingScoreService.submitReport(content, userId); return trainingScoreService.submitReport(content, userId);
} }
//学生端实验报告回显
@GetMapping("/getSubmitAndSaveReport")
public AjaxResult getSubmitAndSaveReport(@RequestParam Long userId){
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
trainingScoreExample.createCriteria().andUseridEqualTo(userId);
List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
if (!sysTrainingScores.isEmpty()){
SysTrainingScore sysTrainingScore = sysTrainingScores.get(0);
return AjaxResult.success(sysTrainingScore.getReportContent());
}
return null;
}
// 老师端文件下载 // 老师端文件下载
@GetMapping("/downloadReport") @GetMapping("/downloadReport")
public AjaxResult downloadReport(@RequestParam HttpServletResponse response, @RequestParam Long id) { public AjaxResult downloadReport(@RequestParam Long id,HttpServletResponse response) {
return trainingScoreService.downloadReport(response, id); return trainingScoreService.downloadReport(response, id);
} }
// 老师端获取文件ID用于下载
@GetMapping("/getReportIdByUserId")
public AjaxResult getReportIdByUserId(@RequestParam Long userId) {
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
trainingScoreExample.createCriteria().andUseridEqualTo(userId);
List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
if (!sysTrainingScores.isEmpty()) {
return AjaxResult.success(sysTrainingScores.get(0));
}
return AjaxResult.error(404, "未查询到文件");
}
// 老师端按班级导出 // 老师端按班级导出
@PostMapping("/exportByClass") @PostMapping("/exportByClass")
public void exportByClass(HttpServletResponse response, String className) { public void exportByClass(HttpServletResponse response,@RequestBody String className) {
// 根据班级名称查询对应的用户列表 // 根据班级名称查询对应的用户列表
List<SysUser> userList = sysUserMapper.selectClassStuNumberNameByClass(className); List<SysUser> userList = sysUserMapper.selectClassStuNumberNameByClass(className);
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample(); SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
@ -158,13 +184,13 @@ public class TrainingScoreController {
ReportDto reportDto = new ReportDto(); ReportDto reportDto = new ReportDto();
reportDto.setFileName(sysTrainingScore.getReportFilename()); reportDto.setFileName(sysTrainingScore.getReportFilename());
if (sysTrainingScore.getReportSubmissionScore() == null) { if (sysTrainingScore.getReportSubmissionScore() == null) {
reportDto.setReportSubmissionScore(0); reportDto.setTrainingReportScore(0.0);
} }
if (sysTrainingScore.getTrainingOperationScore() == null) { if (sysTrainingScore.getTrainingOperationScore() == null) {
reportDto.setTrainingOperationScore(0); reportDto.setTrainingOperationScore(0.0);
} }
reportDto.setReportSubmissionScore(sysTrainingScore.getReportSubmissionScore()); reportDto.setTrainingReportScore(sysTrainingScore.getTrainingReportScore().doubleValue());
reportDto.setTrainingOperationScore(sysTrainingScore.getTrainingOperationScore()); reportDto.setTrainingOperationScore(sysTrainingScore.getTrainingOperationScore().doubleValue());
reportDto.setScoreTotal(sysTrainingScore.getTotalscore()); reportDto.setScoreTotal(sysTrainingScore.getTotalscore());
reportDto.setName(sysUser.getUserName()); reportDto.setName(sysUser.getUserName());
reportDto.setStuClass(sysUser.getStuClass()); reportDto.setStuClass(sysUser.getStuClass());
@ -217,7 +243,9 @@ public class TrainingScoreController {
// 老师端保存修改权重 // 老师端保存修改权重
@PutMapping("/saveOrUpdateWeight") @PutMapping("/saveOrUpdateWeight")
public void saveWeight(@RequestParam Double reportWeight, @RequestParam Double operatorWeight) { public void saveWeight(@RequestBody JSONObject jsonObject) {
Double reportWeight = jsonObject.getDouble("reportWeight");
Double operatorWeight = jsonObject.getDouble("operatorWeight");
SysGradeWeight sysGradeWeight = gradeWeightMapper.selectByPrimaryKey(1L); SysGradeWeight sysGradeWeight = gradeWeightMapper.selectByPrimaryKey(1L);
sysGradeWeight.setReportWeight(reportWeight); sysGradeWeight.setReportWeight(reportWeight);
sysGradeWeight.setOperatorWeight(operatorWeight); sysGradeWeight.setOperatorWeight(operatorWeight);
@ -229,4 +257,24 @@ public class TrainingScoreController {
public SysGradeWeight getWeight() { public SysGradeWeight getWeight() {
return gradeWeightMapper.selectByPrimaryKey(1L); return gradeWeightMapper.selectByPrimaryKey(1L);
} }
// 老师端右侧成绩(为经过权重计算)
@GetMapping("/getReportScore")
public Map<Long,Integer> getWeightReport(){
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
Map<Long,Integer> resultScores= new HashMap<>();
if (!sysTrainingScores.isEmpty()){
for (SysTrainingScore sysTrainingScore : sysTrainingScores) {
if (sysTrainingScore.getTrainingReportScore() != null) {
Integer trainingReportScore = sysTrainingScore.getTrainingReportScore();
Long userid = sysTrainingScore.getUserid();
resultScores.put(userid,trainingReportScore);
}
}
return resultScores;
}
return null;
}
} }

@ -5,8 +5,8 @@ public class ReportDto {
private String stuClass; private String stuClass;
private String stuNumber; private String stuNumber;
private String name; private String name;
private Integer reportSubmissionScore; //报告提交成绩 private Double trainingReportScore; //报告提交成绩
private Integer trainingOperationScore; //实验操作成绩 private Double trainingOperationScore; //实验操作成绩
private Double scoreTotal; //总成绩 private Double scoreTotal; //总成绩
private String fileName; //上传报告名称 private String fileName; //上传报告名称
private Long userId; private Long userId;
@ -25,7 +25,7 @@ public class ReportDto {
"stuClass='" + stuClass + '\'' + "stuClass='" + stuClass + '\'' +
", stuNumber='" + stuNumber + '\'' + ", stuNumber='" + stuNumber + '\'' +
", name='" + name + '\'' + ", name='" + name + '\'' +
", reportSubmissionScore=" + reportSubmissionScore + ", reportSubmissionScore=" + trainingReportScore +
", trainingOperationScore=" + trainingOperationScore + ", trainingOperationScore=" + trainingOperationScore +
", scoreTotal=" + scoreTotal + ", scoreTotal=" + scoreTotal +
", fileName='" + fileName + '\'' + ", fileName='" + fileName + '\'' +
@ -56,22 +56,28 @@ public class ReportDto {
this.name = name; this.name = name;
} }
public Integer getReportSubmissionScore() { public Double getReportSubmissionScore() {
return reportSubmissionScore; return trainingReportScore;
} }
public void setReportSubmissionScore(Integer reportSubmissionScore) { public Double getTrainingReportScore() {
this.reportSubmissionScore = reportSubmissionScore; return trainingReportScore;
} }
public Integer getTrainingOperationScore() { public void setTrainingReportScore(Double trainingReportScore) {
return trainingOperationScore; this.trainingReportScore = trainingReportScore;
} }
public void setTrainingOperationScore(Integer trainingOperationScore) { public void setTrainingOperationScore(Double trainingOperationScore) {
this.trainingOperationScore = trainingOperationScore; this.trainingOperationScore = trainingOperationScore;
} }
public Double getTrainingOperationScore() {
return trainingOperationScore;
}
public Double getScoreTotal() { public Double getScoreTotal() {
return scoreTotal; return scoreTotal;
} }
@ -91,11 +97,11 @@ public class ReportDto {
public ReportDto() { public ReportDto() {
} }
public ReportDto(String stuClass, String stuNumber, String name, Integer reportSubmissionScore, Integer trainingOperationScore, Double scoreTotal, String fileName) { public ReportDto(String stuClass, String stuNumber, String name, Double trainingReportScore, Double trainingOperationScore, Double scoreTotal, String fileName) {
this.stuClass = stuClass; this.stuClass = stuClass;
this.stuNumber = stuNumber; this.stuNumber = stuNumber;
this.name = name; this.name = name;
this.reportSubmissionScore = reportSubmissionScore; this.trainingReportScore = trainingReportScore;
this.trainingOperationScore = trainingOperationScore; this.trainingOperationScore = trainingOperationScore;
this.scoreTotal = scoreTotal; this.scoreTotal = scoreTotal;
this.fileName = fileName; this.fileName = fileName;

@ -97,34 +97,104 @@ public class SysTrainingScoreServiceImpl implements ISysTrainingScoreService {
} }
// @Override
// public PageInfo<ReportDto> teacherGetReport(Integer index, Integer size, Double reportWeight, Double operatorWeight, String keyWord, String stuClass) {
// PageHelper.startPage(index, size);
// List<ReportDto> reportDtoList = new ArrayList<>();
// if (stuClass != null || keyWord != null) {
// List<SysUser> users = sysUserMapper.selectByNameStuNum(stuClass, keyWord);
// for (SysUser user : users) {
// SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
// trainingScoreExample.createCriteria().andUseridEqualTo(user.getUserId());
// List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
// if (!sysTrainingScores.isEmpty()) {
// SysTrainingScore sysTrainingScore = sysTrainingScores.get(0);
// ReportDto reportDto = createReportDto(sysTrainingScore, user, reportWeight, operatorWeight);
// reportDtoList.add(reportDto);
// }
// }
// return new PageInfo<>(reportDtoList);
// }
// List<SysUser> userList = sysUserMapper.selectClassStuNumberName();
// for (SysUser sysUser : userList) {
// SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
// trainingScoreExample.createCriteria().andUseridEqualTo(sysUser.getUserId());
// List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
// if (!sysTrainingScores.isEmpty()) {
// SysTrainingScore sysTrainingScore = sysTrainingScores.get(0);
// ReportDto reportDto = createReportDto(sysTrainingScore, sysUser, reportWeight, operatorWeight);
// reportDtoList.add(reportDto);
// }
// }
// return new PageInfo<>(reportDtoList);
// }
@Override @Override
public PageInfo<ReportDto> teacherGetReport(Integer index, Integer size, Double reportWeight, Double operatorWeight, String keyWord, String stuClass) { public PageInfo<ReportDto> teacherGetReport(Integer index, Integer size, Double reportWeight, Double operatorWeight, String keyWord, String stuClass) {
PageHelper.startPage(index, size); PageHelper.startPage(index, size);
List<ReportDto> reportDtoList = new ArrayList<>(); List<ReportDto> reportDtoList = new ArrayList<>();
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
if (stuClass != null || keyWord != null) { if (stuClass != null || keyWord != null) {
List<SysUser> users = sysUserMapper.selectByNameStuNum(stuClass, keyWord); List<SysUser> users = sysUserMapper.selectByNameStuNum(stuClass, keyWord);
for (SysUser user : users) { for (SysUser user : users) {
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
trainingScoreExample.createCriteria().andUseridEqualTo(user.getUserId()); trainingScoreExample.createCriteria().andUseridEqualTo(user.getUserId());
List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample); List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
if (!sysTrainingScores.isEmpty()) { if (!sysTrainingScores.isEmpty()) {
SysTrainingScore sysTrainingScore = sysTrainingScores.get(0); SysTrainingScore sysTrainingScore = sysTrainingScores.get(0);
// 检查是否已经存在分数
if (sysTrainingScore.getTotalscore() != null &&
sysTrainingScore.getTrainingReportScore() != null &&
sysTrainingScore.getTrainingOperationScore() != null) {
// 使用数据库中的分数创建ReportDto
ReportDto reportDto = new ReportDto(
user.getStuClass(),
user.getStudentNumber(),
user.getUserName(),
sysTrainingScore.getTrainingReportScore().doubleValue(),
sysTrainingScore.getTrainingOperationScore().doubleValue(),
sysTrainingScore.getTotalscore(),
sysTrainingScore.getReportFilename()
);
reportDto.setUserId(user.getUserId());
reportDtoList.add(reportDto);
} else {
// 进行计算分数的逻辑调用createReportDto方法
ReportDto reportDto = createReportDto(sysTrainingScore, user, reportWeight, operatorWeight); ReportDto reportDto = createReportDto(sysTrainingScore, user, reportWeight, operatorWeight);
reportDtoList.add(reportDto); reportDtoList.add(reportDto);
} }
} }
}
return new PageInfo<>(reportDtoList); return new PageInfo<>(reportDtoList);
} }
List<SysUser> userList = sysUserMapper.selectClassStuNumberName(); List<SysUser> userList = sysUserMapper.selectClassStuNumberName();
for (SysUser sysUser : userList) { for (SysUser sysUser : userList) {
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
trainingScoreExample.createCriteria().andUseridEqualTo(sysUser.getUserId()); trainingScoreExample.createCriteria().andUseridEqualTo(sysUser.getUserId());
List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample); List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
if (!sysTrainingScores.isEmpty()) { if (!sysTrainingScores.isEmpty()) {
SysTrainingScore sysTrainingScore = sysTrainingScores.get(0); SysTrainingScore sysTrainingScore = sysTrainingScores.get(0);
if (sysTrainingScore.getTotalscore() != null &&
sysTrainingScore.getTrainingReportScore() != null &&
sysTrainingScore.getTrainingOperationScore() != null) {
// 使用数据库中的分数创建ReportDto
ReportDto reportDto = new ReportDto(
sysUser.getStuClass(),
sysUser.getStudentNumber(),
sysUser.getUserName(),
sysTrainingScore.getTrainingReportScore().doubleValue(),
sysTrainingScore.getTrainingOperationScore().doubleValue(),
sysTrainingScore.getTotalscore(),
sysTrainingScore.getReportFilename()
);
reportDto.setUserId(sysUser.getUserId());
reportDtoList.add(reportDto);
} else {
// 进行计算分数的逻辑调用createReportDto方法
ReportDto reportDto = createReportDto(sysTrainingScore, sysUser, reportWeight, operatorWeight); ReportDto reportDto = createReportDto(sysTrainingScore, sysUser, reportWeight, operatorWeight);
reportDtoList.add(reportDto); reportDtoList.add(reportDto);
} }
} }
}
return new PageInfo<>(reportDtoList); return new PageInfo<>(reportDtoList);
} }
@ -138,15 +208,13 @@ public class SysTrainingScoreServiceImpl implements ISysTrainingScoreService {
private ReportDto createReportDto(SysTrainingScore sysTrainingScore, SysUser user, Double reportWeight, Double operatorWeight) { private ReportDto createReportDto(SysTrainingScore sysTrainingScore, SysUser user, Double reportWeight, Double operatorWeight) {
ReportDto reportDto = new ReportDto(); ReportDto reportDto = new ReportDto();
reportDto.setFileName(sysTrainingScore.getReportFilename()); reportDto.setFileName(sysTrainingScore.getReportFilename());
Integer reportSubmissionScore = sysTrainingScore.getReportSubmissionScore(); // 报告成绩 Integer reportScore = sysTrainingScore.getTrainingReportScore(); // 报告成绩
reportDto.setReportSubmissionScore(reportSubmissionScore);
Integer trainingOperationScore = sysTrainingScore.getTrainingOperationScore(); // 操作成绩 Integer trainingOperationScore = sysTrainingScore.getTrainingOperationScore(); // 操作成绩
reportDto.setTrainingOperationScore(trainingOperationScore);
reportDto.setName(user.getUserName()); reportDto.setName(user.getUserName());
reportDto.setStuClass(user.getStuClass()); reportDto.setStuClass(user.getStuClass());
reportDto.setStuNumber(user.getStudentNumber()); reportDto.setStuNumber(user.getStudentNumber());
reportDto.setUserId(user.getUserId()); reportDto.setUserId(user.getUserId());
if (reportSubmissionScore != null && trainingOperationScore != null) { if (reportScore != null &&reportScore!=0 && trainingOperationScore != null&&trainingOperationScore != 0) {
SysGradeWeight sysGradeWeight = gradeWeightMapper.selectByPrimaryKey(1L); SysGradeWeight sysGradeWeight = gradeWeightMapper.selectByPrimaryKey(1L);
Double oldReportWeight = sysGradeWeight.getReportWeight(); Double oldReportWeight = sysGradeWeight.getReportWeight();
Double oldOperatorWeight = sysGradeWeight.getOperatorWeight(); Double oldOperatorWeight = sysGradeWeight.getOperatorWeight();
@ -165,10 +233,16 @@ public class SysTrainingScoreServiceImpl implements ISysTrainingScoreService {
} else { } else {
operatorWeight = 0.9; // 设置默认权重 operatorWeight = 0.9; // 设置默认权重
} }
Double resultReportScore = reportScore * reportWeight; //报告成绩 加权重后
Double resultOperationScore = trainingOperationScore * operatorWeight; //操作成绩 加权重后
Double totalScore = resultReportScore + resultOperationScore; //总成绩
Double totalScore = (reportSubmissionScore * reportWeight) + (trainingOperationScore * operatorWeight); reportDto.setTrainingReportScore(resultReportScore);
reportDto.setTrainingOperationScore(resultOperationScore);
reportDto.setScoreTotal(totalScore); reportDto.setScoreTotal(totalScore);
sysTrainingScore.setTotalscore(totalScore); sysTrainingScore.setTotalscore(totalScore);
sysTrainingScore.setTrainingReportScore(resultReportScore.intValue());
sysTrainingScore.setTrainingOperationScore(resultOperationScore.intValue());
trainingScoreMapper.updateByPrimaryKeySelective(sysTrainingScore); trainingScoreMapper.updateByPrimaryKeySelective(sysTrainingScore);
gradeWeightMapper.updateByPrimaryKeySelective(sysGradeWeight); gradeWeightMapper.updateByPrimaryKeySelective(sysGradeWeight);
} else { } else {
@ -195,14 +269,14 @@ public class SysTrainingScoreServiceImpl implements ISysTrainingScoreService {
sysTrainingScore.setReportUploadPath(filePath); sysTrainingScore.setReportUploadPath(filePath);
sysTrainingScore.setReportFilename(fileName); sysTrainingScore.setReportFilename(fileName);
trainingScoreMapper.updateByExample(sysTrainingScore, sysTrainingScoreExample); trainingScoreMapper.updateByExample(sysTrainingScore, sysTrainingScoreExample);
return AjaxResult.error("上传成功"); return AjaxResult.success("上传成功");
} else { } else {
if (sysTrainingScore != null) { if (sysTrainingScore != null) {
sysTrainingScore.setReportUploadPath(filePath); sysTrainingScore.setReportUploadPath(filePath);
sysTrainingScore.setReportFilename(fileName); sysTrainingScore.setReportFilename(fileName);
} }
trainingScoreMapper.updateByPrimaryKeySelective(sysTrainingScore); trainingScoreMapper.updateByPrimaryKeySelective(sysTrainingScore);
return AjaxResult.error("上传成功"); return AjaxResult.success("上传成功");
} }
} }
return null; return null;
@ -223,7 +297,7 @@ public class SysTrainingScoreServiceImpl implements ISysTrainingScoreService {
sysTrainingScore.setReportContent(content); sysTrainingScore.setReportContent(content);
trainingScoreMapper.updateByExample(sysTrainingScore, trainingScoreExample); trainingScoreMapper.updateByExample(sysTrainingScore, trainingScoreExample);
} }
return null; return AjaxResult.success("提交成功");
} }
@ -234,11 +308,10 @@ public class SysTrainingScoreServiceImpl implements ISysTrainingScoreService {
@Override @Override
public AjaxResult downloadReport(HttpServletResponse response, Long id) { public AjaxResult downloadReport(HttpServletResponse response, Long id) {
SysTrainingScoreExample trainingScoreExample = new SysTrainingScoreExample();
trainingScoreExample.createCriteria().andUseridEqualTo(id);
// 根据id获取文件路径信息 // 根据id获取文件路径信息
SysTrainingScoreExample sysTrainingScoreExample = new SysTrainingScoreExample(); List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(trainingScoreExample);
sysTrainingScoreExample.createCriteria().andUseridEqualTo(id);
List<SysTrainingScore> sysTrainingScores = trainingScoreMapper.selectByExample(sysTrainingScoreExample);
if (sysTrainingScores.isEmpty()) { if (sysTrainingScores.isEmpty()) {
return AjaxResult.error(404, "报告不存在"); return AjaxResult.error(404, "报告不存在");
} }

@ -87,12 +87,12 @@
</sql> </sql>
<select id="selectClassStuNumberName" resultMap="SysUserResult"> <select id="selectClassStuNumberName" resultMap="SysUserResult">
SELECT studentnumber, stuclass, user_name SELECT studentnumber, stuclass, user_name, user_id
FROM sys_user FROM sys_user
</select> </select>
<select id="selectClassStuNumberNameByClass" resultMap="SysUserResult"> <select id="selectClassStuNumberNameByClass" resultMap="SysUserResult">
SELECT studentnumber, stuclass, user_name SELECT studentnumber, stuclass, user_name, user_id
FROM sys_user FROM sys_user
<where> <where>
<if test="stuClass != null and stuClass !=''"> <if test="stuClass != null and stuClass !=''">

Loading…
Cancel
Save