|
|
|
@ -2,8 +2,11 @@ package com.sztzjy.marketing.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
|
|
import com.sztzjy.marketing.config.exception.handler.ServiceException;
|
|
|
|
|
import com.sztzjy.marketing.entity.*;
|
|
|
|
|
import com.sztzjy.marketing.entity.dto.*;
|
|
|
|
@ -13,14 +16,19 @@ import com.sztzjy.marketing.service.UserBehaviorProfilingAnaService;
|
|
|
|
|
import com.sztzjy.marketing.util.BigDecimalUtils;
|
|
|
|
|
import com.sztzjy.marketing.util.ConvertUtil;
|
|
|
|
|
import com.sztzjy.marketing.util.PdfUtil;
|
|
|
|
|
import com.sztzjy.marketing.util.ResultEntity;
|
|
|
|
|
import com.sztzjy.marketing.util.compute.ScoringUtil;
|
|
|
|
|
import com.sztzjy.marketing.util.file.IFileUtil;
|
|
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.mock.web.MockMultipartFile;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import util.convertPDF.PDFConvertUtil;
|
|
|
|
|
|
|
|
|
@ -29,9 +37,12 @@ import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@ -269,6 +280,7 @@ public class StuConceptBlockServiceImpl implements StuConceptBlockService {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public StuPracticalTrainingReport upload(MultipartFile file, StuBlockProductWithDTO stuBlockProductWithBLOBs) {
|
|
|
|
|
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
@ -702,6 +714,162 @@ public class StuConceptBlockServiceImpl implements StuConceptBlockService {
|
|
|
|
|
anaService.personalScoreEntry(stuScoreDetailsList,tchConceptualTechnologyWeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//上传实验报告
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ResultEntity newUpload(MultipartFile file, StuBlockProductWithDTO stuBlockProductWithBLOBs) {
|
|
|
|
|
if (!StringUtils.hasText(stuBlockProductWithBLOBs.getSchoolId()))
|
|
|
|
|
{
|
|
|
|
|
throw new RuntimeException("学校ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.hasText(stuBlockProductWithBLOBs.getUserId()))
|
|
|
|
|
{
|
|
|
|
|
throw new RuntimeException("用户ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.hasText(stuBlockProductWithBLOBs.getModule()))
|
|
|
|
|
{
|
|
|
|
|
throw new RuntimeException("模块不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//上传文件
|
|
|
|
|
//判断文件格式是否符合条件
|
|
|
|
|
String sp = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String [] array = {"docx","doc", "pdf", "jpg", "png", "mp4", "avi"};
|
|
|
|
|
List<String> collect = Arrays.stream(array).collect(Collectors.toList());
|
|
|
|
|
if (!collect.contains(sp)){
|
|
|
|
|
throw new RuntimeException("上传格式仅支持:Word,PDF,图片,视频");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询是第几次上传文件
|
|
|
|
|
StuPracticalTrainingReportExample example = new StuPracticalTrainingReportExample();
|
|
|
|
|
example.createCriteria().andSchoolIdEqualTo(stuBlockProductWithBLOBs.getSchoolId())
|
|
|
|
|
.andModuleEqualTo(stuBlockProductWithBLOBs.getModule())
|
|
|
|
|
.andUseridEqualTo(stuBlockProductWithBLOBs.getUserId());
|
|
|
|
|
|
|
|
|
|
List<StuPracticalTrainingReport> stuPracticalTrainingReportList = stuPracticalTrainingReportMapper.selectByExample(example);
|
|
|
|
|
if (CollectionUtils.isEmpty(stuPracticalTrainingReportList)){
|
|
|
|
|
//第一次上传
|
|
|
|
|
|
|
|
|
|
StuPracticalTrainingReport stuPracticalTrainingReport = uploadByReport(file,stuBlockProductWithBLOBs);
|
|
|
|
|
|
|
|
|
|
stuPracticalTrainingReport.setAscription(String.valueOf(1));
|
|
|
|
|
stuPracticalTrainingReportMapper.insertSelective(stuPracticalTrainingReport);
|
|
|
|
|
|
|
|
|
|
stuPracticalTrainingReportList.add(stuPracticalTrainingReport);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK,stuPracticalTrainingReportList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if (stuPracticalTrainingReportList.size() == 1){
|
|
|
|
|
|
|
|
|
|
StuPracticalTrainingReport stuPracticalTrainingReport = uploadByReport(file,stuBlockProductWithBLOBs);
|
|
|
|
|
stuPracticalTrainingReport.setAscription(String.valueOf(2));
|
|
|
|
|
stuPracticalTrainingReportMapper.insertSelective(stuPracticalTrainingReport);
|
|
|
|
|
|
|
|
|
|
stuPracticalTrainingReportList.add(stuPracticalTrainingReport);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK,stuPracticalTrainingReportList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if (stuPracticalTrainingReportList.size() == 2){
|
|
|
|
|
|
|
|
|
|
StuPracticalTrainingReport stuPracticalTrainingReport = uploadByReport(file,stuBlockProductWithBLOBs);
|
|
|
|
|
stuPracticalTrainingReport.setAscription(String.valueOf(3));
|
|
|
|
|
stuPracticalTrainingReportMapper.insertSelective(stuPracticalTrainingReport);
|
|
|
|
|
stuPracticalTrainingReportList.add(stuPracticalTrainingReport);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK,stuPracticalTrainingReportList);
|
|
|
|
|
}else {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"系统允许您上传至多三份实验报告!",stuPracticalTrainingReportList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ResultEntity downReportByZip(HttpServletResponse response,String userId,String module,String reportName) {
|
|
|
|
|
StuPracticalTrainingReportExample example = new StuPracticalTrainingReportExample();
|
|
|
|
|
StuPracticalTrainingReportExample.Criteria criteria = example.createCriteria()
|
|
|
|
|
.andModuleEqualTo(module)
|
|
|
|
|
.andUseridEqualTo(userId);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.hasText(reportName)) {
|
|
|
|
|
criteria.andReportNameEqualTo(reportName);
|
|
|
|
|
List<StuPracticalTrainingReport> stuPracticalTrainingReportList = stuPracticalTrainingReportMapper.selectByExample(example);
|
|
|
|
|
if (CollectionUtils.isEmpty(stuPracticalTrainingReportList)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
fileUtil.download(response, stuPracticalTrainingReportList.get(0).getUrl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// //批量下载
|
|
|
|
|
List<StuPracticalTrainingReport> stuPracticalTrainingReportList = stuPracticalTrainingReportMapper.selectByExample(example);
|
|
|
|
|
if (CollectionUtils.isEmpty(stuPracticalTrainingReportList)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK);
|
|
|
|
|
} else {
|
|
|
|
|
List<String> urlList = stuPracticalTrainingReportList.stream()
|
|
|
|
|
.map(item -> filePath + item.getUrl())
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
// 创建字节输出流和ZIP输出流
|
|
|
|
|
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream)) {
|
|
|
|
|
|
|
|
|
|
// 将文件逐个添加到ZIP中
|
|
|
|
|
for (String filePathStr : urlList) {
|
|
|
|
|
File file = new File(filePathStr);
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
try (FileInputStream fis = new FileInputStream(file)) {
|
|
|
|
|
zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
|
|
|
|
|
IOUtils.copy(fis, zipOutputStream);
|
|
|
|
|
zipOutputStream.closeEntry();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 完成ZIP写入
|
|
|
|
|
zipOutputStream.finish();
|
|
|
|
|
|
|
|
|
|
// 设置响应头,触发浏览器下载
|
|
|
|
|
response.setContentType("application/zip");
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"reports.zip\"");
|
|
|
|
|
response.setContentLength(byteArrayOutputStream.size());
|
|
|
|
|
|
|
|
|
|
// 将ZIP文件内容写入响应
|
|
|
|
|
try (OutputStream outputStream = response.getOutputStream()) {
|
|
|
|
|
byteArrayOutputStream.writeTo(outputStream);
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private StuPracticalTrainingReport uploadByReport(MultipartFile file, StuBlockProductWithDTO stuBlockProductWithBLOBs) {
|
|
|
|
|
|
|
|
|
|
StuPracticalTrainingReport stuPracticalTrainingReport = new StuPracticalTrainingReport();
|
|
|
|
|
String upload = fileUtil.upload(file);
|
|
|
|
|
|
|
|
|
|
stuPracticalTrainingReport.setId((int) IdUtil.getSnowflakeNextId());
|
|
|
|
|
|
|
|
|
|
stuPracticalTrainingReport.setModule(stuBlockProductWithBLOBs.getModule());
|
|
|
|
|
stuPracticalTrainingReport.setSize((int) file.getSize());
|
|
|
|
|
stuPracticalTrainingReport.setReportName(file.getOriginalFilename());
|
|
|
|
|
stuPracticalTrainingReport.setSchoolId(stuBlockProductWithBLOBs.getSchoolId());
|
|
|
|
|
stuPracticalTrainingReport.setUserid(stuBlockProductWithBLOBs.getUserId());
|
|
|
|
|
stuPracticalTrainingReport.setUploadTime(new Date());
|
|
|
|
|
stuPracticalTrainingReport.setUrl(upload);
|
|
|
|
|
|
|
|
|
|
return stuPracticalTrainingReport;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
|
|
|
|
|
// 创建一个临时文件
|
|
|
|
|