From 04d56ec755c2f95013919cf512fa744d51057c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B2=85?= <907037276@qq.com> Date: Fri, 21 Jul 2023 10:21:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReportController.java | 21 +++++++++++ .../forex/trading_trading/entity/Member.java | 6 +-- .../service/GradeWeightService.java | 8 ++++ .../service/ReportService.java | 37 ++++++++++++++++--- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sztzjy/forex/trading_trading/controller/ReportController.java b/src/main/java/com/sztzjy/forex/trading_trading/controller/ReportController.java index 86e0c14..d4c37d9 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/controller/ReportController.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/controller/ReportController.java @@ -1,13 +1,18 @@ package com.sztzjy.forex.trading_trading.controller; +import com.sztzjy.forex.trading_trading.annotation.Permission; +import com.sztzjy.forex.trading_trading.annotation.aspect.PermissionType; import com.sztzjy.forex.trading_trading.entity.ReportWithBLOBs; import com.sztzjy.forex.trading_trading.service.ReportService; import com.sztzjy.forex.trading_trading.util.ResultEntity; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Api(tags = "实验报告") @@ -29,4 +34,20 @@ public class ReportController { public ResultEntity submitReport(@RequestBody ReportWithBLOBs report) { return new ResultEntity<>(reportService.submitReport(report)); } + + + @ApiOperation("教师端--对实训报告评分") + @PostMapping("review") + @Permission(codes = PermissionType.TRAINING_PLAN_MANAGEMENT_EDIT) + public ResultEntity review(@RequestParam String id, + @RequestParam Double score) { + reportService.review(id, score); + return new ResultEntity(HttpStatus.OK); + } + + @ApiOperation("教师端--实训报告下载") + @GetMapping("download") + public void download(@RequestParam String id, HttpServletResponse response) { + reportService.download(id,response); + } } diff --git a/src/main/java/com/sztzjy/forex/trading_trading/entity/Member.java b/src/main/java/com/sztzjy/forex/trading_trading/entity/Member.java index 4f0d91d..4dbfd9f 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/entity/Member.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/entity/Member.java @@ -197,7 +197,7 @@ public class Member { * * @mbg.generated Wed Jul 19 15:55:18 CST 2023 */ - private Integer reportScore; + private Double reportScore; /** * @@ -720,7 +720,7 @@ public class Member { * * @mbg.generated Wed Jul 19 15:55:18 CST 2023 */ - public Integer getReportScore() { + public Double getReportScore() { return reportScore; } @@ -732,7 +732,7 @@ public class Member { * * @mbg.generated Wed Jul 19 15:55:18 CST 2023 */ - public void setReportScore(Integer reportScore) { + public void setReportScore(Double reportScore) { this.reportScore = reportScore; } diff --git a/src/main/java/com/sztzjy/forex/trading_trading/service/GradeWeightService.java b/src/main/java/com/sztzjy/forex/trading_trading/service/GradeWeightService.java index ab9ef58..fb16280 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/service/GradeWeightService.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/service/GradeWeightService.java @@ -83,4 +83,12 @@ public class GradeWeightService { return findWeightByWeightId(gradeWeights.getWeightId()); } + public Double findReportScore(String id,Double score) { + GradeWeight gradeWeight = gradeWeightMapper.selectByPrimaryKey(id); + if (gradeWeight == null) { + return null; + } + return gradeWeight.getReportScoreScale() * score / 100; + } + } diff --git a/src/main/java/com/sztzjy/forex/trading_trading/service/ReportService.java b/src/main/java/com/sztzjy/forex/trading_trading/service/ReportService.java index 138d750..5a7d291 100644 --- a/src/main/java/com/sztzjy/forex/trading_trading/service/ReportService.java +++ b/src/main/java/com/sztzjy/forex/trading_trading/service/ReportService.java @@ -1,14 +1,14 @@ package com.sztzjy.forex.trading_trading.service; -import com.sztzjy.forex.trading_trading.entity.Member; -import com.sztzjy.forex.trading_trading.entity.MemberExample; -import com.sztzjy.forex.trading_trading.entity.ReportExample; -import com.sztzjy.forex.trading_trading.entity.ReportWithBLOBs; +import com.sztzjy.forex.trading_trading.entity.*; import com.sztzjy.forex.trading_trading.mappers.MemberMapper; import com.sztzjy.forex.trading_trading.mappers.ReportMapper; +import com.sztzjy.forex.trading_trading.util.file.IFileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; +import javax.servlet.http.HttpServletResponse; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -20,6 +20,12 @@ public class ReportService { private ReportMapper reportsMapper; @Autowired private MemberMapper memberMapper; + @Autowired + private GradeWeightService gradeWeightService; + @Autowired + private TrainingService trainingService; + @Autowired + private IFileUtil fileUtil; private static final String SERVER_DIRECTORY = "D:\\waihui\\"; @@ -33,7 +39,7 @@ public class ReportService { Member member = members.get(0); ReportExample reportExample = new ReportExample(); reportExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId); - Integer reportScore = member.getReportScore(); + Double reportScore = member.getReportScore(); List reportWithBLOBs = reportsMapper.selectByExampleWithBLOBs(reportExample); if (!reportWithBLOBs.isEmpty()) { if (reportScore == null) { @@ -55,7 +61,7 @@ public class ReportService { Member member = members.get(0); ReportExample reportExample = new ReportExample(); reportExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId); - Integer reportScore = member.getReportScore(); + Double reportScore = member.getReportScore(); List reportWithBLOBs = reportsMapper.selectByExampleWithBLOBs(reportExample); try { if (reportScore == null) { @@ -89,4 +95,23 @@ public class ReportService { } return "老师已评分,禁止上传"; } + + + public void review(String reportId,Double score){ + Report report = reportsMapper.selectByPrimaryKey(reportId); + Assert.isTrue(report!=null&&report.getMemberId()!=null,"报告不存在"); + Member member = memberMapper.selectByPrimaryKey(report.getMemberId()); + Assert.isTrue(member!=null&&member.getTrainingId()!=null,"数据异常"); + Training training = trainingService.findById(member.getTrainingId()); + Assert.isTrue(training!=null&&training.getWeightId()!=null,"数据异常"); + member.setReportScore(gradeWeightService.findReportScore(training.getWeightId(),score)); + memberMapper.updateByPrimaryKey(member); + } + + + public void download(String id, HttpServletResponse response){ + Report report = reportsMapper.selectByPrimaryKey(id); + Assert.isTrue(report!=null&&report.getFilePath()!=null,"报告不存在"); + fileUtil.download(response,report.getFilePath(),report.getFileName()); + } }