|
|
@@ -250,145 +250,152 @@ public class ProgrammeService {
|
|
|
}
|
|
|
|
|
|
File destDir = TempFile.createTempDirectory("import");
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
- boolean zip = Pattern.matches("zip", FilenameUtils.getExtension(originalFilename));
|
|
|
- boolean rar = false;
|
|
|
- if (!zip) {
|
|
|
- rar = Pattern.matches("rar", FilenameUtils.getExtension(originalFilename));
|
|
|
- }
|
|
|
- if (rar) {
|
|
|
- FileUtils.unrar(file.getInputStream(), destDir);
|
|
|
- } else if (zip) {
|
|
|
- try {
|
|
|
- ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
|
|
|
- } catch (Exception e) {
|
|
|
- ZipUtil.unzip(file.getInputStream(), destDir, Charset.forName("gbk"));
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new BusinessException("最能上传zip或者rar压缩包");
|
|
|
- }
|
|
|
+ try {
|
|
|
|
|
|
|
|
|
- File xlsxFile = FileUtils.findInDir(destDir, null);
|
|
|
- if (xlsxFile == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- InputStream indicatorStream = new FileInputStream(xlsxFile);
|
|
|
- UploadDataListener<ProgUploadDTO> listener = new UploadDataListener<>();
|
|
|
- List<ProgUploadDTO> dtos = EasyExcel.read(indicatorStream, ProgUploadDTO.class, listener).sheet().doReadSync();
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ boolean zip = Pattern.matches("zip", FilenameUtils.getExtension(originalFilename));
|
|
|
+ boolean rar = false;
|
|
|
+ if (!zip) {
|
|
|
+ rar = Pattern.matches("rar", FilenameUtils.getExtension(originalFilename));
|
|
|
+ }
|
|
|
+ if (rar) {
|
|
|
+ FileUtils.unrar(file.getInputStream(), destDir);
|
|
|
+ } else if (zip) {
|
|
|
+ try {
|
|
|
+ ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
|
|
|
+ } catch (Exception e) {
|
|
|
+ ZipUtil.unzip(file.getInputStream(), destDir, Charset.forName("gbk"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("最能上传zip或者rar压缩包");
|
|
|
+ }
|
|
|
|
|
|
-// 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))
|
|
|
- .stream()
|
|
|
- .collect(Collectors.groupingBy(Setting::getFlag, Collectors.toMap(Setting::getName, Setting::getId)));
|
|
|
+ File xlsxFile = FileUtils.findInDir(destDir, null);
|
|
|
+ if (xlsxFile == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ InputStream indicatorStream = new FileInputStream(xlsxFile);
|
|
|
+ UploadDataListener<ProgUploadDTO> listener = new UploadDataListener<>();
|
|
|
+ List<ProgUploadDTO> dtos = EasyExcel.read(indicatorStream, ProgUploadDTO.class, listener)
|
|
|
+ .sheet()
|
|
|
+ .doReadSync();
|
|
|
|
|
|
- Map<String, Long> gradeMap = gradingOrganizationRepo.findAll()
|
|
|
- .stream()
|
|
|
- .collect(Collectors.toMap(GradingOrganization::getName, GradingOrganization::getId));
|
|
|
+ Map<Integer, Map<String, Long>> mapMap = settingRepo.findAllByFlagIn(CollUtil.newArrayList(3, 4))
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(Setting::getFlag, Collectors.toMap(Setting::getName, Setting::getId)));
|
|
|
|
|
|
- Map<String, ArtType> artTypeMap = artTypeRepo.findAll()
|
|
|
- .stream()
|
|
|
- .collect(Collectors.toMap(ArtType::getName, artType -> artType));
|
|
|
-
|
|
|
-
|
|
|
- List<Participant> participants = new ArrayList<>();
|
|
|
- Long pid = null;
|
|
|
- for (ProgUploadDTO dto : dtos) {
|
|
|
- if (dto.getName() != null && dto.getSpecialty() != null) {
|
|
|
- Programme programme = new Programme(dto);
|
|
|
- System.out.println(dto.getSpecialty());
|
|
|
- ArtType specialty = artTypeMap.get(dto.getSpecialty());
|
|
|
- programme.setOrganizationId(organization.getId());
|
|
|
- programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
|
|
|
- programme.setPerformanceId(performance);
|
|
|
-
|
|
|
- // 专业
|
|
|
- if (ObjectUtil.isNotNull(specialty)){
|
|
|
- programme.setSpecialtyId(specialty.getId());
|
|
|
- }
|
|
|
+ Map<String, Long> gradeMap = gradingOrganizationRepo.findAll()
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(GradingOrganization::getName, GradingOrganization::getId));
|
|
|
|
|
|
- // 节目状态
|
|
|
- programme.setProgrammeStatus(ProgrammeStatus.INITIAL);
|
|
|
- String level = dto.getLevel();
|
|
|
- if (StrUtil.isNotBlank(level)) {
|
|
|
- level = level.substring(0, 2);
|
|
|
- }
|
|
|
- if (dto.getCompetitionGroup().equals(CompetitionGroup.SINGLE)) {
|
|
|
- programme.setLevelSettingId(mapMap.get(3).get(level));
|
|
|
- } else if (dto.getCompetitionGroup().equals(CompetitionGroup.COLLECTIVE)) {
|
|
|
- programme.setLevelSettingId(mapMap.get(4).get(level));
|
|
|
- }
|
|
|
+ Map<String, ArtType> artTypeMap = artTypeRepo.findAll()
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ArtType::getName, artType -> artType));
|
|
|
+
|
|
|
+
|
|
|
+ List<Participant> participants = new ArrayList<>();
|
|
|
+ Long pid = null;
|
|
|
+ for (ProgUploadDTO dto : dtos) {
|
|
|
+ if (dto.getName() != null && dto.getSpecialty() != null) {
|
|
|
+ Programme programme = new Programme(dto);
|
|
|
+ System.out.println(dto.getSpecialty());
|
|
|
+ ArtType specialty = artTypeMap.get(dto.getSpecialty());
|
|
|
+ programme.setOrganizationId(organization.getId());
|
|
|
+ programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
|
|
|
+ programme.setPerformanceId(performance);
|
|
|
+
|
|
|
+ // 专业
|
|
|
+ if (ObjectUtil.isNotNull(specialty)) {
|
|
|
+ programme.setSpecialtyId(specialty.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 节目状态
|
|
|
+ programme.setProgrammeStatus(ProgrammeStatus.INITIAL);
|
|
|
+ String level = dto.getLevel();
|
|
|
+ if (StrUtil.isNotBlank(level)) {
|
|
|
+ level = level.substring(0, 2);
|
|
|
+ }
|
|
|
+ if (dto.getCompetitionGroup().equals(CompetitionGroup.SINGLE)) {
|
|
|
+ programme.setLevelSettingId(mapMap.get(3).get(level));
|
|
|
+ } else if (dto.getCompetitionGroup().equals(CompetitionGroup.COLLECTIVE)) {
|
|
|
+ programme.setLevelSettingId(mapMap.get(4).get(level));
|
|
|
+ }
|
|
|
|
|
|
- File uploadFile = FileUtils.findInDir(destDir, dto.getName());
|
|
|
- if (dto.getVideo() != null) {
|
|
|
+ File uploadFile = FileUtils.findInDir(destDir, dto.getName());
|
|
|
+ if (dto.getVideo() != null) {
|
|
|
// File uploadFile = new File(destDir, dto.getVideo());
|
|
|
- uploadFile = FileUtils.findInDir(destDir, dto.getVideo());
|
|
|
+ uploadFile = FileUtils.findInDir(destDir, dto.getVideo());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(uploadFile) && uploadFile.exists()) {
|
|
|
+ // 视频
|
|
|
+ if (!specialty.getCode().startsWith("03")) {
|
|
|
+ // 上传
|
|
|
+ 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);
|
|
|
+ } else {
|
|
|
+ // 图片
|
|
|
+ programme.setAnnex(this.saveImg(uploadFile));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ pid = programmeRepo.save(programme).getId();
|
|
|
}
|
|
|
- if (ObjectUtil.isNotNull(uploadFile) && uploadFile.exists()) {
|
|
|
- // 视频
|
|
|
- if (!specialty.getCode().startsWith("03")) {
|
|
|
- // 上传
|
|
|
- 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);
|
|
|
+
|
|
|
+ Participant participant = new Participant(dto);
|
|
|
+ if (ObjectUtil.isNotNull(dto.getParticipantBirthday())) {
|
|
|
+ if (dto.getParticipantBirthday().contains("/")) {
|
|
|
+ LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT1));
|
|
|
+ participant.setBirthday(birthday);
|
|
|
+ } else if (dto.getParticipantBirthday().contains("-")) {
|
|
|
+ LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT));
|
|
|
+ participant.setBirthday(birthday);
|
|
|
} else {
|
|
|
- // 图片
|
|
|
- programme.setAnnex(this.saveImg(uploadFile));
|
|
|
+ throw new BusinessException("日期格式错误!");
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
- pid = programmeRepo.save(programme).getId();
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- Participant participant = new Participant(dto);
|
|
|
- if (ObjectUtil.isNotNull(dto.getParticipantBirthday())) {
|
|
|
- if (dto.getParticipantBirthday().contains("/")) {
|
|
|
- LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT1));
|
|
|
- participant.setBirthday(birthday);
|
|
|
- } else if (dto.getParticipantBirthday().contains("-")) {
|
|
|
- LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT));
|
|
|
- participant.setBirthday(birthday);
|
|
|
+ participant.setProgrammeId(pid);
|
|
|
+ participant.setPerformanceId(performance);
|
|
|
+ participants.add(participant);
|
|
|
+ File uploadImg;
|
|
|
+ if (dto.getImg() != null) {
|
|
|
+// File uploadFile = new File(destDir, dto.getImg());
|
|
|
+ uploadImg = FileUtils.findInDir(destDir, dto.getImg());
|
|
|
} else {
|
|
|
- throw new BusinessException("日期格式错误!");
|
|
|
+ uploadImg = FileUtils.findInDir(destDir, dto.getIdNo() + "证件照");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(uploadImg) && uploadImg.exists()) {
|
|
|
+ participant.setImg(this.saveImg(uploadImg));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- participant.setProgrammeId(pid);
|
|
|
- participant.setPerformanceId(performance);
|
|
|
- participants.add(participant);
|
|
|
- File uploadImg;
|
|
|
- if (dto.getImg() != null) {
|
|
|
-// File uploadFile = new File(destDir, dto.getImg());
|
|
|
- uploadImg = FileUtils.findInDir(destDir, dto.getImg());
|
|
|
- } else {
|
|
|
- uploadImg = FileUtils.findInDir(destDir, dto.getIdNo() + "证件照");
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotNull(uploadImg) && uploadImg.exists()) {
|
|
|
- participant.setImg(this.saveImg(uploadImg));
|
|
|
+ File uploadCertificate;
|
|
|
+ if (dto.getCertificate() != null) {
|
|
|
+ uploadCertificate = FileUtils.findInDir(destDir, dto.getCertificate());
|
|
|
+ } else {
|
|
|
+ uploadCertificate = FileUtils.findInDir(destDir, dto.getIdNo() + "证书");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(uploadCertificate) && uploadCertificate.exists()) {
|
|
|
+ participant.setCertificate(this.saveImg(uploadCertificate));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- File uploadCertificate;
|
|
|
- if (dto.getCertificate() != null) {
|
|
|
- uploadCertificate = FileUtils.findInDir(destDir, dto.getCertificate());
|
|
|
- } else {
|
|
|
- uploadCertificate = FileUtils.findInDir(destDir, dto.getIdNo() + "证书");
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotNull(uploadCertificate) && uploadCertificate.exists()) {
|
|
|
- participant.setCertificate(this.saveImg(uploadCertificate));
|
|
|
- }
|
|
|
- }
|
|
|
+ participantRepo.saveAll(participants);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ FileUtils.delFiles(destDir);
|
|
|
|
|
|
- participantRepo.saveAll(participants);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private String saveImg(File uploadFile) throws FileNotFoundException {
|