|
@@ -7,12 +7,10 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.izouma.wenlvju.config.DateConfig;
|
|
|
import com.izouma.wenlvju.domain.*;
|
|
import com.izouma.wenlvju.domain.*;
|
|
|
import com.izouma.wenlvju.domain.performance.*;
|
|
import com.izouma.wenlvju.domain.performance.*;
|
|
|
-import com.izouma.wenlvju.dto.ArrangeProgrammeDTO;
|
|
|
|
|
-import com.izouma.wenlvju.dto.PageQuery;
|
|
|
|
|
-import com.izouma.wenlvju.dto.ProgrammeDTO;
|
|
|
|
|
-import com.izouma.wenlvju.dto.ProgrammeScoreDTO;
|
|
|
|
|
|
|
+import com.izouma.wenlvju.dto.*;
|
|
|
import com.izouma.wenlvju.enums.CompetitionGroup;
|
|
import com.izouma.wenlvju.enums.CompetitionGroup;
|
|
|
import com.izouma.wenlvju.enums.SignedIn;
|
|
import com.izouma.wenlvju.enums.SignedIn;
|
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
@@ -41,9 +39,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.nio.file.Paths;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -98,7 +97,7 @@ public class ProgrammeService {
|
|
|
List<Long> settingIds = new ArrayList<>();
|
|
List<Long> settingIds = new ArrayList<>();
|
|
|
content.forEach(programme -> settingIds.add(programme.getLevelSettingId()));
|
|
content.forEach(programme -> settingIds.add(programme.getLevelSettingId()));
|
|
|
|
|
|
|
|
- Map<Long, String> performanceMap = performanceRepo.findAll()
|
|
|
|
|
|
|
+ Map<Long, String> performanceMap = performanceRepo.findAllByPublishTrue()
|
|
|
.stream()
|
|
.stream()
|
|
|
.collect(Collectors.toMap(Performance::getId, Performance::getName));
|
|
.collect(Collectors.toMap(Performance::getId, Performance::getName));
|
|
|
|
|
|
|
@@ -186,6 +185,10 @@ public class ProgrammeService {
|
|
|
@Transactional(rollbackOn = Exception.class)
|
|
@Transactional(rollbackOn = Exception.class)
|
|
|
public void upload(MultipartFile file, Long userId) throws IOException {
|
|
public void upload(MultipartFile file, Long userId) throws IOException {
|
|
|
Organization organization = organizationRepo.findByUserId(userId).orElseThrow(new BusinessException("无记录"));
|
|
Organization organization = organizationRepo.findByUserId(userId).orElseThrow(new BusinessException("无记录"));
|
|
|
|
|
+ Long performance = performanceRepo.findNow(LocalDate.now());
|
|
|
|
|
+ if (ObjectUtil.isNull(performance)) {
|
|
|
|
|
+ throw new BusinessException("没有正在报名中的展演活动");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
File destDir = TempFile.createTempDirectory("import");
|
|
File destDir = TempFile.createTempDirectory("import");
|
|
|
ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
|
|
ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
|
|
@@ -201,12 +204,12 @@ public class ProgrammeService {
|
|
|
|
|
|
|
|
|
|
|
|
|
InputStream indicatorStream = new FileInputStream(xlsxFile);
|
|
InputStream indicatorStream = new FileInputStream(xlsxFile);
|
|
|
- UploadDataListener<ProgrammeDTO> listener = new UploadDataListener<>();
|
|
|
|
|
- List<ProgrammeDTO> dtos = EasyExcel.read(indicatorStream, ProgrammeDTO.class, listener).sheet().doReadSync();
|
|
|
|
|
|
|
+ UploadDataListener<ProgUploadDTO> listener = new UploadDataListener<>();
|
|
|
|
|
+ List<ProgUploadDTO> dtos = EasyExcel.read(indicatorStream, ProgUploadDTO.class, listener).sheet().doReadSync();
|
|
|
|
|
|
|
|
- Map<String, Long> performanceMap = performanceRepo.findAll()
|
|
|
|
|
- .stream()
|
|
|
|
|
- .collect(Collectors.toMap(Performance::getName, Performance::getId));
|
|
|
|
|
|
|
+// Map<String, Long> performanceMap = performanceRepo.findAll()
|
|
|
|
|
+// .stream()
|
|
|
|
|
+// .collect(Collectors.toMap(Performance::getName, Performance::getId));
|
|
|
|
|
|
|
|
Map<Integer, Map<String, Long>> mapMap = settingRepo.findAllByFlagIn(CollUtil.newArrayList(3, 4))
|
|
Map<Integer, Map<String, Long>> mapMap = settingRepo.findAllByFlagIn(CollUtil.newArrayList(3, 4))
|
|
|
.stream()
|
|
.stream()
|
|
@@ -223,12 +226,12 @@ public class ProgrammeService {
|
|
|
|
|
|
|
|
List<Participant> participants = new ArrayList<>();
|
|
List<Participant> participants = new ArrayList<>();
|
|
|
Long pid = null;
|
|
Long pid = null;
|
|
|
- for (ProgrammeDTO dto : dtos) {
|
|
|
|
|
|
|
+ for (ProgUploadDTO dto : dtos) {
|
|
|
if (dto.getName() != null && dto.getSpecialty() != null) {
|
|
if (dto.getName() != null && dto.getSpecialty() != null) {
|
|
|
Programme programme = new Programme(dto);
|
|
Programme programme = new Programme(dto);
|
|
|
programme.setOrganizationId(organization.getId());
|
|
programme.setOrganizationId(organization.getId());
|
|
|
programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
|
|
programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
|
|
|
- programme.setPerformanceId(performanceMap.get(dto.getPerformance()));
|
|
|
|
|
|
|
+ programme.setPerformanceId(performance);
|
|
|
programme.setSpecialtyId(artTypeMap.get(dto.getSpecialty()));
|
|
programme.setSpecialtyId(artTypeMap.get(dto.getSpecialty()));
|
|
|
String level = dto.getLevel();
|
|
String level = dto.getLevel();
|
|
|
if (StrUtil.isNotBlank(level)) {
|
|
if (StrUtil.isNotBlank(level)) {
|
|
@@ -240,39 +243,49 @@ public class ProgrammeService {
|
|
|
programme.setLevelSettingId(mapMap.get(4).get(level));
|
|
programme.setLevelSettingId(mapMap.get(4).get(level));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ File uploadFile = FileUtils.findByName(destDir, dto.getName());
|
|
|
if (dto.getVideo() != null) {
|
|
if (dto.getVideo() != null) {
|
|
|
- File uploadFile = new File(destDir, dto.getVideo());
|
|
|
|
|
- if (uploadFile.exists()) {
|
|
|
|
|
- // 上传
|
|
|
|
|
- String videoPath = "video/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
|
|
- + RandomStringUtils.randomAlphabetic(8)
|
|
|
|
|
- + "." + FilenameUtils.getExtension(uploadFile.getName());
|
|
|
|
|
- String url = storageService.uploadFromInputStream(new FileInputStream(uploadFile), videoPath);
|
|
|
|
|
- VideoObject vo = new VideoObject();
|
|
|
|
|
-// vo.setPoster(posterUrl);
|
|
|
|
|
- vo.setSrc(url);
|
|
|
|
|
- programme.setVideo(vo);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// File uploadFile = new File(destDir, dto.getVideo());
|
|
|
|
|
+ uploadFile = FileUtils.findByName(destDir, dto.getVideo());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isNotNull(uploadFile) && uploadFile.exists()) {
|
|
|
|
|
+ // 上传
|
|
|
|
|
+ String videoPath = "video/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
|
|
+ + RandomStringUtils.randomAlphabetic(8)
|
|
|
|
|
+ + "." + FilenameUtils.getExtension(uploadFile.getName());
|
|
|
|
|
+ String url = storageService.uploadFromInputStream(new FileInputStream(uploadFile), videoPath);
|
|
|
|
|
+ VideoObject vo = new VideoObject();
|
|
|
|
|
+ vo.setSrc(url);
|
|
|
|
|
+ programme.setVideo(vo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pid = programmeRepo.save(programme).getId();
|
|
pid = programmeRepo.save(programme).getId();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Participant participant = new Participant(dto);
|
|
Participant participant = new Participant(dto);
|
|
|
|
|
+ LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT));
|
|
|
|
|
+ participant.setBirthday(birthday);
|
|
|
participant.setProgrammeId(pid);
|
|
participant.setProgrammeId(pid);
|
|
|
participants.add(participant);
|
|
participants.add(participant);
|
|
|
-
|
|
|
|
|
|
|
+ File uploadImg;
|
|
|
if (dto.getImg() != null) {
|
|
if (dto.getImg() != null) {
|
|
|
- File uploadFile = new File(destDir, dto.getImg());
|
|
|
|
|
- if (uploadFile.exists()) {
|
|
|
|
|
- participant.setImg(this.saveImg(uploadFile));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// File uploadFile = new File(destDir, dto.getImg());
|
|
|
|
|
+ uploadImg = FileUtils.findByName(destDir, dto.getImg());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uploadImg = FileUtils.findByName(destDir, dto.getIdNo() + "证件照");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isNotNull(uploadImg) && uploadImg.exists()) {
|
|
|
|
|
+ participant.setImg(this.saveImg(uploadImg));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ File uploadCertificate;
|
|
|
if (dto.getCertificate() != null) {
|
|
if (dto.getCertificate() != null) {
|
|
|
- File uploadFile = new File(destDir, dto.getCertificate());
|
|
|
|
|
- if (uploadFile.exists()) {
|
|
|
|
|
- participant.setCertificate(this.saveImg(uploadFile));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ uploadCertificate = FileUtils.findByName(destDir, dto.getCertificate());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uploadCertificate = FileUtils.findByName(destDir, dto.getIdNo() + "证书");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isNotNull(uploadCertificate) && uploadCertificate.exists()) {
|
|
|
|
|
+ participant.setCertificate(this.saveImg(uploadCertificate));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -288,9 +301,10 @@ public class ProgrammeService {
|
|
|
|
|
|
|
|
public void excelTemp(HttpServletResponse response) throws IOException {
|
|
public void excelTemp(HttpServletResponse response) throws IOException {
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
- File file = new File(this.getClass().getResource("/templates/Programme.xlsx").getPath());
|
|
|
|
|
- InputStream is = new FileInputStream(file);
|
|
|
|
|
|
|
+// File file = new File(this.getClass().getResource("/templates/Programme.xlsx").getPath());
|
|
|
|
|
+// InputStream is = new FileInputStream(file);
|
|
|
|
|
|
|
|
|
|
+ InputStream is = getClass().getResourceAsStream("/templates/Programme.xlsx");
|
|
|
byte[] buffer = new byte[1024];
|
|
byte[] buffer = new byte[1024];
|
|
|
int len;
|
|
int len;
|
|
|
while ((len = is.read(buffer)) > -1) {
|
|
while ((len = is.read(buffer)) > -1) {
|