业务编写

pull/1/head
陈沅 2 years ago
parent 88889b23ab
commit 8b95942c5d

@ -1,9 +1,14 @@
package com.sztzjy.forex.trading_trading.controller; package com.sztzjy.forex.trading_trading.controller;
import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess;
import com.sztzjy.forex.trading_trading.annotation.Permission; import com.sztzjy.forex.trading_trading.annotation.Permission;
import com.sztzjy.forex.trading_trading.annotation.aspect.PermissionType; import com.sztzjy.forex.trading_trading.annotation.aspect.PermissionType;
import com.sztzjy.forex.trading_trading.config.security.JwtUser;
import com.sztzjy.forex.trading_trading.config.security.TokenProvider;
import com.sztzjy.forex.trading_trading.entity.Member;
import com.sztzjy.forex.trading_trading.entity.Report; import com.sztzjy.forex.trading_trading.entity.Report;
import com.sztzjy.forex.trading_trading.entity.ReportWithBLOBs; import com.sztzjy.forex.trading_trading.entity.ReportWithBLOBs;
import com.sztzjy.forex.trading_trading.service.MemberService;
import com.sztzjy.forex.trading_trading.service.ReportService; import com.sztzjy.forex.trading_trading.service.ReportService;
import com.sztzjy.forex.trading_trading.util.ResultEntity; import com.sztzjy.forex.trading_trading.util.ResultEntity;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -22,15 +27,19 @@ import java.io.IOException;
public class ReportController { public class ReportController {
@Autowired @Autowired
private ReportService reportService; private ReportService reportService;
@Autowired
private MemberService memberService;
@ApiOperation("学生端--上传实训报告")
@PostMapping("/uploadReport") @PostMapping("/uploadReport")
public ResultEntity<String> uploadReport(@RequestParam("file") MultipartFile file, public ResultEntity uploadReport(@RequestParam("file")@RequestPart(name = "file") MultipartFile file,
@RequestParam String memberId, @RequestParam String memberId,
@RequestParam String fileName, @RequestParam String fileName) {
@RequestParam String tariningId) throws IOException { Member member = memberService.selectByPrimaryKey(memberId);
return new ResultEntity<>(reportService.uploadReport(file.getInputStream(), fileName, memberId, tariningId)); reportService.uploadReport(file, fileName, member);
return new ResultEntity(HttpStatus.OK);
} }
@ApiOperation("学生端--提交实训报告")
@PostMapping("/submitReport") @PostMapping("/submitReport")
public ResultEntity<String> submitReport(@RequestBody ReportWithBLOBs report) { public ResultEntity<String> submitReport(@RequestBody ReportWithBLOBs report) {
return new ResultEntity<>(reportService.submitReport(report)); return new ResultEntity<>(reportService.submitReport(report));
@ -46,9 +55,11 @@ public class ReportController {
return new ResultEntity(HttpStatus.OK); return new ResultEntity(HttpStatus.OK);
} }
@AnonymousAccess
@ApiOperation("教师端--实训报告下载") @ApiOperation("教师端--实训报告下载")
@GetMapping("download") @GetMapping("download")
public void download(@RequestParam String id, HttpServletResponse response) { public void download(@RequestParam String id, String TOKEN,HttpServletResponse response) {
TokenProvider.getJWTUser(TOKEN);
reportService.download(id, response); reportService.download(id, response);
} }

@ -1,5 +1,6 @@
package com.sztzjy.forex.trading_trading.service; package com.sztzjy.forex.trading_trading.service;
import com.sztzjy.forex.trading_trading.config.security.JwtUser;
import com.sztzjy.forex.trading_trading.entity.*; import com.sztzjy.forex.trading_trading.entity.*;
import com.sztzjy.forex.trading_trading.mappers.MemberMapper; import com.sztzjy.forex.trading_trading.mappers.MemberMapper;
import com.sztzjy.forex.trading_trading.mappers.ReportMapper; import com.sztzjy.forex.trading_trading.mappers.ReportMapper;
@ -7,6 +8,8 @@ import com.sztzjy.forex.trading_trading.util.file.IFileUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; import java.io.InputStream;
@ -52,7 +55,7 @@ public class ReportService {
} }
// 指定服务器目录 // 指定服务器目录
public String uploadReport(InputStream fileInputStream, String fileName, String memberId,String trainingId) { public String uploadReport(InputStream fileInputStream, String fileName, String memberId, String trainingId) {
MemberExample memberExample = new MemberExample(); MemberExample memberExample = new MemberExample();
memberExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId); memberExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
List<Member> members = memberMapper.selectByExample(memberExample); List<Member> members = memberMapper.selectByExample(memberExample);
@ -61,28 +64,51 @@ public class ReportService {
reportExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId); reportExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
Double reportScore = member.getReportScore(); Double reportScore = member.getReportScore();
List<ReportWithBLOBs> reportWithBLOBs = reportsMapper.selectByExampleWithBLOBs(reportExample); List<ReportWithBLOBs> reportWithBLOBs = reportsMapper.selectByExampleWithBLOBs(reportExample);
if (reportScore == null) { if (reportScore == null) {
String filePath = fileUtil.upload(fileName, fileInputStream); String filePath = fileUtil.upload(fileName, fileInputStream);
if (!reportWithBLOBs.isEmpty()) { if (!reportWithBLOBs.isEmpty()) {
ReportWithBLOBs resultReport = reportWithBLOBs.get(0); ReportWithBLOBs resultReport = reportWithBLOBs.get(0);
resultReport.setFilePath(filePath); resultReport.setFilePath(filePath);
resultReport.setFileName(fileName); resultReport.setFileName(fileName);
resultReport.setTrainingId(trainingId); resultReport.setTrainingId(trainingId);
reportsMapper.updateByExampleSelective(resultReport, reportExample); reportsMapper.updateByExampleSelective(resultReport, reportExample);
} else { } else {
ReportWithBLOBs report = new ReportWithBLOBs(); ReportWithBLOBs report = new ReportWithBLOBs();
report.setFileName(filePath); report.setFileName(filePath);
report.setFilePath(fileName); report.setFilePath(fileName);
report.setMemberId(memberId); report.setMemberId(memberId);
report.setTrainingId(trainingId); report.setTrainingId(trainingId);
reportsMapper.insert(report); reportsMapper.insert(report);
}
return "上传成功";
} }
return "上传成功";
}
return "老师已评分,禁止上传"; return "老师已评分,禁止上传";
} }
public void uploadReport(MultipartFile file, String fileName, Member member) {
String filePath = fileUtil.upload(file);
ReportExample reportExample = new ReportExample();
reportExample.createCriteria().andMemberIdEqualTo(member.getMemberId());
List<ReportWithBLOBs> reports = reportsMapper.selectByExampleWithBLOBs(reportExample);
if(reports!=null&&reports.size()>0){
ReportWithBLOBs report = reports.get(0);
if(StringUtils.hasText(report.getFilePath())){
fileUtil.remove(report.getFilePath());
}
report.setFilePath(filePath);
report.setFileName(fileName);
reportsMapper.updateByExample(report,reportExample);
}else{
ReportWithBLOBs report = new ReportWithBLOBs();
report.setFileName(fileName);
report.setFilePath(filePath);
report.setMemberId(member.getMemberId());
report.setTrainingId(member.getTrainingId());
reportsMapper.insert(report);
}
}
// // 指定服务器目录 // // 指定服务器目录
// public String uploadReport(InputStream fileInputStream, String fileName, String memberId,String trainingId) { // public String uploadReport(InputStream fileInputStream, String fileName, String memberId,String trainingId) {
@ -128,31 +154,30 @@ public class ReportService {
// } // }
public void review(String reportId, Double score) {
public void review(String reportId,Double score){
Report report = reportsMapper.selectByPrimaryKey(reportId); Report report = reportsMapper.selectByPrimaryKey(reportId);
Assert.isTrue(report!=null&&report.getMemberId()!=null,"报告不存在"); Assert.isTrue(report != null && report.getMemberId() != null, "报告不存在");
Member member = memberMapper.selectByPrimaryKey(report.getMemberId()); Member member = memberMapper.selectByPrimaryKey(report.getMemberId());
Assert.isTrue(member!=null&&member.getTrainingId()!=null,"数据异常"); Assert.isTrue(member != null && member.getTrainingId() != null, "数据异常");
Training training = trainingService.findById(member.getTrainingId()); Training training = trainingService.findById(member.getTrainingId());
Assert.isTrue(training!=null&&training.getWeightId()!=null,"数据异常"); Assert.isTrue(training != null && training.getWeightId() != null, "数据异常");
member.setReportScore(gradeWeightService.findReportScore(training.getWeightId(),score)); member.setReportScore(gradeWeightService.findReportScore(training.getWeightId(), score));
memberMapper.updateByPrimaryKey(member); memberMapper.updateByPrimaryKey(member);
} }
public void download(String id, HttpServletResponse response){ public void download(String id, HttpServletResponse response) {
Report report = reportsMapper.selectByPrimaryKey(id); Report report = reportsMapper.selectByPrimaryKey(id);
Assert.isTrue(report!=null&&report.getFilePath()!=null,"报告不存在"); Assert.isTrue(report != null && report.getFilePath() != null, "报告不存在");
fileUtil.download(response,report.getFileName(),report.getFilePath()); fileUtil.download(response, report.getFileName(), report.getFilePath());
} }
public Report findByMemberId(String memberId){ public Report findByMemberId(String memberId) {
ReportExample reportExample = new ReportExample(); ReportExample reportExample = new ReportExample();
ReportExample.Criteria criteria = reportExample.createCriteria(); ReportExample.Criteria criteria = reportExample.createCriteria();
criteria.andMemberIdEqualTo(memberId); criteria.andMemberIdEqualTo(memberId);
List<Report> reports = reportsMapper.selectByExample(reportExample); List<Report> reports = reportsMapper.selectByExample(reportExample);
if(reports!=null&&reports.size()>0){ if (reports != null && reports.size() > 0) {
return reports.get(0); return reports.get(0);
} }
return null; return null;

@ -65,7 +65,7 @@ public class LocalFileUtil implements IFileUtil{
public boolean remove(String path) { public boolean remove(String path) {
if (!StringUtils.hasText(path)) return false; if (!StringUtils.hasText(path)) return false;
File file = new File(getFullPath(path)); File file = new File(getFullPath(path));
Assert.isTrue(file.exists(), "文件已被删除或不存在该文件"); if (!file.exists()) return false;
return file.delete(); return file.delete();
} }

Loading…
Cancel
Save