Merge remote-tracking branch 'origin/master'
commit
43048f4a66
@ -0,0 +1,40 @@
|
||||
package com.sztzjy.forex.trading_trading.dto;
|
||||
|
||||
|
||||
import com.sztzjy.forex.trading_trading.entity.Member;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("教师端用户操作数据出参")
|
||||
@Getter
|
||||
@Setter
|
||||
@Data
|
||||
public class MemberVO {
|
||||
|
||||
@ApiModelProperty("实训名称")
|
||||
public String trainingName;
|
||||
@ApiModelProperty("班级名称")
|
||||
public String classGrade;
|
||||
@ApiModelProperty("学生姓名")
|
||||
public String name;
|
||||
@ApiModelProperty("学生学号")
|
||||
public String studentNumber;
|
||||
@ApiModelProperty("累计收益")
|
||||
public Double cumulativeProfitLoss;
|
||||
@ApiModelProperty("收益率")
|
||||
public Double yield;
|
||||
@ApiModelProperty("交易实训成绩")
|
||||
public Double tradeTrainingScore;
|
||||
@ApiModelProperty("实训报告成绩")
|
||||
public Double trainingReportScore;
|
||||
@ApiModelProperty("总成绩")
|
||||
public Double totalScore;
|
||||
@ApiModelProperty("排名")
|
||||
public Integer stuRank;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.sztzjy.forex.trading_trading.service;
|
||||
|
||||
|
||||
import com.sztzjy.forex.trading_trading.mappers.TrainingMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
*/
|
||||
@Service
|
||||
public class ScheduledTask {
|
||||
|
||||
@Autowired
|
||||
TrainingMapper trainingMapper;
|
||||
|
||||
|
||||
@Scheduled(cron = "0 * * * * *") // 修改实训状态 每分钟执行一次
|
||||
public void updateTrainingStatus() {
|
||||
trainingMapper.updateTrainingStatusToInProgress();
|
||||
trainingMapper.updateTrainingStatusToEnd();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.sztzjy.forex.trading_trading.util.excel;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Excel通用数据对象封装 若需要复杂表头和更多样式等、需定义导出模板
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
public class ExcelData {
|
||||
private List<List<String>> contents;
|
||||
private ExcelData(){
|
||||
this.contents = new ArrayList<>();
|
||||
}
|
||||
public ExcelData addRow(List<Object> rowData){
|
||||
List<String> dataList = rowData.stream().map(i -> i==null?null:i.toString()).collect(Collectors.toList());
|
||||
this.contents.add(dataList);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建无标题文档
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public static ExcelData create(){
|
||||
return ExcelData.create(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建有标题文档
|
||||
* @param titleList 内容|标题
|
||||
* @return 数据对象
|
||||
*/
|
||||
public static ExcelData create(List<String> titleList){
|
||||
ExcelData excelData = new ExcelData();
|
||||
if(titleList!=null && !titleList.isEmpty())
|
||||
excelData.contents.add(titleList);
|
||||
return excelData;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.sztzjy.forex.trading_trading.util.excel;
|
||||
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ExcelProvider {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ExcelProvider.class);
|
||||
|
||||
/**
|
||||
* 简单通用excel导出 若需要复杂表头和更多样式等、需定义导出模板
|
||||
* 输出无样式的excel
|
||||
*
|
||||
* @param data 待导出的数据
|
||||
*/
|
||||
public static void SimpleExcelExport(ExcelData data, OutputStream out){
|
||||
Assert.notNull(data, "无可导出的数据");
|
||||
Assert.notEmpty(data.getContents(), "无可导出的数据");
|
||||
ExcelWriter bigWriter = ExcelUtil.getBigWriter();
|
||||
bigWriter.write(data.getContents());
|
||||
bigWriter.flush(out,true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ExcelData excelData = ExcelData.create(Arrays.asList("t1","t2"))
|
||||
.addRow(Arrays.asList("11","12"))
|
||||
.addRow(Arrays.asList("21","22"));
|
||||
FileOutputStream fileOut = new FileOutputStream("D:/111.xlsx");
|
||||
ExcelProvider.SimpleExcelExport(excelData,fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
package com.sztzjy.forex.trading_trading.util.file;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class LocalFileUtil implements IFileUtil{
|
||||
|
||||
private final static List<String> excludeSp = Arrays.asList("exe", "bin", "sh");
|
||||
|
||||
private final String localPath;
|
||||
|
||||
public LocalFileUtil(String localPath) {
|
||||
this.localPath = localPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(MultipartFile file) {
|
||||
return upload(null, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(String objectName, InputStream fileIn) {
|
||||
Assert.notNull(fileIn, "文件不能为空");
|
||||
Assert.hasText(objectName, "文件名为空");
|
||||
Assert.isTrue(objectName.lastIndexOf(".") > 0, "文件名称需携带扩展后缀");
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
String relativePath = getDiskRelativePath(objectName, null);
|
||||
File file = new File(getFullPath(relativePath));
|
||||
file.getParentFile().mkdirs();
|
||||
out = new FileOutputStream(file);
|
||||
byte[] buff = new byte[4096];
|
||||
int len;
|
||||
while ((len = fileIn.read(buff)) != -1) {
|
||||
out.write(buff, 0, len);
|
||||
}
|
||||
out.flush();
|
||||
return relativePath;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalArgumentException("上传文件失败,IO错误");
|
||||
} finally {
|
||||
try {
|
||||
fileIn.close();
|
||||
if (out != null) out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(String path) {
|
||||
if (!StringUtils.hasText(path)) return false;
|
||||
File file = new File(getFullPath(path));
|
||||
Assert.isTrue(file.exists(), "文件已被删除或不存在该文件");
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(HttpServletResponse response, String fileName, String relativePath) {
|
||||
Assert.hasText(relativePath, "路径为空");
|
||||
System.out.println("------------------------------------" + getFullPath(relativePath));
|
||||
File file = new File(getFullPath(relativePath));
|
||||
Assert.isTrue(file.exists(), "附件不存在");
|
||||
String sp = relativePath.substring(relativePath.lastIndexOf(".") + 1);
|
||||
Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误");
|
||||
if (!StringUtils.hasText(fileName)) {
|
||||
fileName = file.getName().substring(0, file.getName().lastIndexOf("."));
|
||||
}
|
||||
InputStream fis = null;
|
||||
try {
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode((fileName + "." + sp), CharsetUtil.UTF_8));
|
||||
fis = new BufferedInputStream(Files.newInputStream(file.toPath()));
|
||||
response.addHeader("Content-Length", String.valueOf(fis.available()));
|
||||
byte[] buff = new byte[4096];
|
||||
int len;
|
||||
while ((len = fis.read(buff)) != -1) {
|
||||
response.getOutputStream().write(buff, 0, len);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("下载文件失败: " + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null) fis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(HttpServletResponse response, String relativePath) {
|
||||
download(response, null, relativePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullPath(String relativePath) {
|
||||
if (!relativePath.startsWith("/")) {
|
||||
relativePath = "/" + relativePath;
|
||||
}
|
||||
return localPath + relativePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix(String fileName) {
|
||||
Assert.hasText(fileName, "文件名不存在!");
|
||||
if (fileName.lastIndexOf(".") < 0) {
|
||||
return null;
|
||||
}
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
public String upload(String fileName, MultipartFile file) {
|
||||
return upload(fileName, file, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDiskRelativePath(String fileName, String suffix) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date d = new Date();
|
||||
c.setTime(d);
|
||||
String year = Integer.toString(c.get(Calendar.YEAR));
|
||||
String month = Integer.toString(c.get(Calendar.MONTH) + 1);
|
||||
String day = Integer.toString(c.get(Calendar.DATE));
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append("/").append(year)
|
||||
.append("/").append(month)
|
||||
.append("/").append(day)
|
||||
.append("/").append(fileName);
|
||||
if (StringUtils.hasText(suffix)) path.append(".").append(suffix);
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
private String upload(String fileName, MultipartFile file, String relativePath) {
|
||||
Assert.isTrue(!file.isEmpty(), "文件不存在");
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (fileName == null) fileName = IdUtil.simpleUUID();
|
||||
String sp = getSuffix(originalFilename);
|
||||
Assert.notNull(sp, "文件类型错误");
|
||||
Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误");
|
||||
try {
|
||||
String filePath;
|
||||
if (relativePath == null) {
|
||||
filePath = getDiskRelativePath(fileName, sp);
|
||||
} else {
|
||||
relativePath = relativePath.endsWith("/") ? relativePath : relativePath + "/";
|
||||
filePath = relativePath + fileName + "." + sp;
|
||||
}
|
||||
|
||||
File destFile = new File(getFullPath(filePath));
|
||||
destFile.getParentFile().mkdirs();
|
||||
file.transferTo(destFile);
|
||||
return filePath;
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new IllegalArgumentException("上传文件失败,FileNotFound错误");
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("上传文件失败,IO错误");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue