|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
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.mappers.MemberMapper;
|
|
|
|
|
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.stereotype.Service;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
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.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
|
|
|
|
|
List<Member> members = memberMapper.selectByExample(memberExample);
|
|
|
|
@ -61,28 +64,51 @@ public class ReportService {
|
|
|
|
|
reportExample.createCriteria().andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId);
|
|
|
|
|
Double reportScore = member.getReportScore();
|
|
|
|
|
List<ReportWithBLOBs> reportWithBLOBs = reportsMapper.selectByExampleWithBLOBs(reportExample);
|
|
|
|
|
if (reportScore == null) {
|
|
|
|
|
String filePath = fileUtil.upload(fileName, fileInputStream);
|
|
|
|
|
if (!reportWithBLOBs.isEmpty()) {
|
|
|
|
|
ReportWithBLOBs resultReport = reportWithBLOBs.get(0);
|
|
|
|
|
resultReport.setFilePath(filePath);
|
|
|
|
|
resultReport.setFileName(fileName);
|
|
|
|
|
resultReport.setTrainingId(trainingId);
|
|
|
|
|
reportsMapper.updateByExampleSelective(resultReport, reportExample);
|
|
|
|
|
} else {
|
|
|
|
|
ReportWithBLOBs report = new ReportWithBLOBs();
|
|
|
|
|
report.setFileName(filePath);
|
|
|
|
|
report.setFilePath(fileName);
|
|
|
|
|
report.setMemberId(memberId);
|
|
|
|
|
report.setTrainingId(trainingId);
|
|
|
|
|
reportsMapper.insert(report);
|
|
|
|
|
}
|
|
|
|
|
return "上传成功";
|
|
|
|
|
if (reportScore == null) {
|
|
|
|
|
String filePath = fileUtil.upload(fileName, fileInputStream);
|
|
|
|
|
if (!reportWithBLOBs.isEmpty()) {
|
|
|
|
|
ReportWithBLOBs resultReport = reportWithBLOBs.get(0);
|
|
|
|
|
resultReport.setFilePath(filePath);
|
|
|
|
|
resultReport.setFileName(fileName);
|
|
|
|
|
resultReport.setTrainingId(trainingId);
|
|
|
|
|
reportsMapper.updateByExampleSelective(resultReport, reportExample);
|
|
|
|
|
} else {
|
|
|
|
|
ReportWithBLOBs report = new ReportWithBLOBs();
|
|
|
|
|
report.setFileName(filePath);
|
|
|
|
|
report.setFilePath(fileName);
|
|
|
|
|
report.setMemberId(memberId);
|
|
|
|
|
report.setTrainingId(trainingId);
|
|
|
|
|
reportsMapper.insert(report);
|
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
@ -128,22 +154,32 @@ public class ReportService {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void review(String reportId,Double score){
|
|
|
|
|
public void review(String reportId, Double score) {
|
|
|
|
|
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());
|
|
|
|
|
Assert.isTrue(member!=null&&member.getTrainingId()!=null,"数据异常");
|
|
|
|
|
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));
|
|
|
|
|
Assert.isTrue(training != null && training.getWeightId() != null, "数据异常");
|
|
|
|
|
member.setReportScore(gradeWeightService.findReportScore(training.getWeightId(), score));
|
|
|
|
|
memberMapper.updateByPrimaryKey(member);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void download(String id, HttpServletResponse response){
|
|
|
|
|
public void download(String id, HttpServletResponse response) {
|
|
|
|
|
Report report = reportsMapper.selectByPrimaryKey(id);
|
|
|
|
|
Assert.isTrue(report!=null&&report.getFilePath()!=null,"报告不存在");
|
|
|
|
|
fileUtil.download(response,report.getFileName(),report.getFilePath());
|
|
|
|
|
Assert.isTrue(report != null && report.getFilePath() != null, "报告不存在");
|
|
|
|
|
fileUtil.download(response, report.getFileName(), report.getFilePath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Report findByMemberId(String memberId) {
|
|
|
|
|
ReportExample reportExample = new ReportExample();
|
|
|
|
|
ReportExample.Criteria criteria = reportExample.createCriteria();
|
|
|
|
|
criteria.andMemberIdEqualTo(memberId);
|
|
|
|
|
List<Report> reports = reportsMapper.selectByExample(reportExample);
|
|
|
|
|
if (reports != null && reports.size() > 0) {
|
|
|
|
|
return reports.get(0);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|