|
|
@@ -40,12 +40,13 @@ import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.io.*;
|
|
|
-import java.math.BigDecimal;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -98,9 +99,9 @@ public class ProgrammeService {
|
|
|
if (ProgrammeStatus.INITIAL.equals(orig.getProgrammeStatus())) {
|
|
|
Performance performance = performanceRepo.findById(orig.getPerformanceId())
|
|
|
.orElseThrow(new BusinessException("无展演活动"));
|
|
|
- if (LocalDate.now().isAfter(performance.getEndDate())) {
|
|
|
- throw new BusinessException("活动已报名结束!");
|
|
|
- }
|
|
|
+// if (LocalDate.now().isAfter(performance.getEndDate())) {
|
|
|
+// throw new BusinessException("活动已报名结束!");
|
|
|
+// }
|
|
|
}
|
|
|
ObjUtils.merge(orig, record);
|
|
|
orig.setParentSpecialtyId(artTypeService.getParent(orig.getSpecialtyId()));
|
|
|
@@ -108,9 +109,9 @@ public class ProgrammeService {
|
|
|
} else {
|
|
|
Performance performance = performanceRepo.findById(record.getPerformanceId())
|
|
|
.orElseThrow(new BusinessException("无展演活动"));
|
|
|
- if (LocalDate.now().isAfter(performance.getEndDate())) {
|
|
|
- throw new BusinessException("活动已报名结束!");
|
|
|
- }
|
|
|
+// if (LocalDate.now().isAfter(performance.getEndDate())) {
|
|
|
+// throw new BusinessException("活动已报名结束!");
|
|
|
+// }
|
|
|
record.setParentSpecialtyId(artTypeService.getParent(record.getSpecialtyId()));
|
|
|
record = programmeRepo.save(record);
|
|
|
}
|
|
|
@@ -126,6 +127,28 @@ public class ProgrammeService {
|
|
|
return record;
|
|
|
}
|
|
|
|
|
|
+ public Page<Programme> all2(PageQuery pageQuery) {
|
|
|
+ Map<String, Object> query = pageQuery.getQuery();
|
|
|
+ Object code = query.get("code");
|
|
|
+ String artCode = null;
|
|
|
+ if (ObjectUtil.isNotNull(code)) {
|
|
|
+ artCode = Convert.convert(String.class, code);
|
|
|
+ query.remove("code");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ArtType> artTypes = artTypeRepo.findAll();
|
|
|
+
|
|
|
+ String finalArtCode = artCode;
|
|
|
+ return programmeRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = JpaUtils.toPredicates(pageQuery, Programme.class, root, criteriaQuery, criteriaBuilder);
|
|
|
+ if (StrUtil.isNotBlank(finalArtCode)) {
|
|
|
+ and.add(root.get("specialtyId").in(artTypeService.getIds(artTypes, finalArtCode)));
|
|
|
+ }
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public Page<ProgrammeDTO> backAll(PageQuery pageQuery) {
|
|
|
Map<String, Object> query = pageQuery.getQuery();
|
|
|
@@ -139,7 +162,7 @@ public class ProgrammeService {
|
|
|
List<ArtType> artTypes = artTypeRepo.findAll();
|
|
|
|
|
|
String finalArtCode = artCode;
|
|
|
- Page<Programme> all = programmeRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ Page<Programme> all = programmeRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
List<Predicate> and = JpaUtils.toPredicates(pageQuery, Programme.class, root, criteriaQuery, criteriaBuilder);
|
|
|
if (StrUtil.isNotBlank(finalArtCode)) {
|
|
|
and.add(root.get("specialtyId").in(artTypeService.getIds(artTypes, finalArtCode)));
|
|
|
@@ -241,135 +264,177 @@ public class ProgrammeService {
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackOn = Exception.class)
|
|
|
- public void upload(MultipartFile file, Long userId) throws IOException {
|
|
|
+ public void upload(MultipartFile file, Long userId) throws Exception {
|
|
|
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");
|
|
|
- ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
|
|
|
-
|
|
|
-// File xlsxFile = FileUtils.findExcel1(destDir);
|
|
|
-// if (xlsxFile == null) {
|
|
|
-// Map<String, File> map = FileUtils.findExcel(destDir);
|
|
|
-// if (map == null) return;
|
|
|
-//
|
|
|
-// xlsxFile = map.get("file");
|
|
|
-// destDir = map.get("destDir");
|
|
|
+// Long performance = performanceRepo.findNow(LocalDate.now());
|
|
|
+// if (ObjectUtil.isNull(performance)) {
|
|
|
+// throw new BusinessException("没有正在报名中的展演活动");
|
|
|
// }
|
|
|
- File xlsxFile = FileUtils.folderMethod1(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> performanceMap = performanceRepo.findAll()
|
|
|
-// .stream()
|
|
|
-// .collect(Collectors.toMap(Performance::getName, Performance::getId));
|
|
|
+ // 临时开启
|
|
|
+ Long performance = performanceRepo.findByYear(String.valueOf(LocalDate.now().getYear())).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 destDir = TempFile.createTempDirectory("import");
|
|
|
+ try {
|
|
|
|
|
|
- Map<String, Long> gradeMap = gradingOrganizationRepo.findAll()
|
|
|
- .stream()
|
|
|
- .collect(Collectors.toMap(GradingOrganization::getName, GradingOrganization::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);
|
|
|
- ArtType specialty = artTypeMap.get(dto.getSpecialty());
|
|
|
- programme.setOrganizationId(organization.getId());
|
|
|
- programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
|
|
|
- programme.setPerformanceId(performance);
|
|
|
- programme.setSpecialtyId(specialty.getId());
|
|
|
- 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));
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ boolean zip = Pattern.matches("zip", FilenameUtils.getExtension(originalFilename));
|
|
|
+ boolean rar = false;
|
|
|
+ if (!zip) {
|
|
|
+ rar = Pattern.matches("rar", FilenameUtils.getExtension(originalFilename));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException("最能上传zip或者rar压缩包");
|
|
|
+ }
|
|
|
|
|
|
- File uploadFile = FileUtils.folderMethod1(destDir, dto.getName());
|
|
|
- if (dto.getVideo() != null) {
|
|
|
-// File uploadFile = new File(destDir, dto.getVideo());
|
|
|
- uploadFile = FileUtils.folderMethod1(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);
|
|
|
+
|
|
|
+ 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<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, Long> gradeMap = gradingOrganizationRepo.findAll()
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(GradingOrganization::getName, GradingOrganization::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);
|
|
|
+ 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());
|
|
|
} else {
|
|
|
- // 图片
|
|
|
- programme.setAnnex(this.saveImg(uploadFile));
|
|
|
+ throw new BusinessException("专业名称不正确,仔细核对专业表");
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // 节目状态
|
|
|
+ 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));
|
|
|
+ }
|
|
|
|
|
|
- pid = programmeRepo.save(programme).getId();
|
|
|
- }
|
|
|
+ File uploadFile = FileUtils.findInDir(destDir, dto.getName());
|
|
|
+ if (dto.getVideo() != null) {
|
|
|
+ uploadFile = FileUtils.findInDir(destDir, dto.getVideo());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotNull(uploadFile) && uploadFile.exists()) {
|
|
|
+ // 视频
|
|
|
+ if (ObjectUtil.isNotNull(specialty)) {
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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 {
|
|
|
- throw new BusinessException("日期格式错误!");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ pid = programmeRepo.save(programme).getId();
|
|
|
}
|
|
|
|
|
|
+ Participant participant = new Participant(dto);
|
|
|
+ if (ObjectUtil.isNotNull(dto.getParticipantBirthday())) {
|
|
|
+ if (dto.getParticipantBirthday().contains("/")) {
|
|
|
+ try {
|
|
|
+ LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT1));
|
|
|
+ participant.setBirthday(birthday);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException("日期格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (dto.getParticipantBirthday().contains("-")) {
|
|
|
+ try {
|
|
|
+ LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT));
|
|
|
+ participant.setBirthday(birthday);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException("日期格式错误");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("日期格式错误!");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- participant.setProgrammeId(pid);
|
|
|
- participants.add(participant);
|
|
|
- File uploadImg;
|
|
|
- if (dto.getImg() != null) {
|
|
|
+ participant.setProgrammeId(pid);
|
|
|
+ participant.setPerformanceId(performance);
|
|
|
+ participants.add(participant);
|
|
|
+ File uploadImg;
|
|
|
+ if (dto.getImg() != null) {
|
|
|
// File uploadFile = new File(destDir, dto.getImg());
|
|
|
- uploadImg = FileUtils.folderMethod1(destDir, dto.getImg());
|
|
|
- } else {
|
|
|
- uploadImg = FileUtils.folderMethod1(destDir, dto.getIdNo() + "证件照");
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotNull(uploadImg) && uploadImg.exists()) {
|
|
|
- participant.setImg(this.saveImg(uploadImg));
|
|
|
- }
|
|
|
+ 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.folderMethod1(destDir, dto.getCertificate());
|
|
|
- } else {
|
|
|
- uploadCertificate = FileUtils.folderMethod1(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);
|
|
|
+ participantRepo.saveAll(participants);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ FileUtils.delFiles(destDir);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private String saveImg(File uploadFile) throws FileNotFoundException {
|
|
|
@@ -562,19 +627,19 @@ public class ProgrammeService {
|
|
|
List<Programme> programmes = programmeRepo.findAllByPerformanceIdAndProgrammeStatusAndReviewArrangeIdIsNull(performanceId, ProgrammeStatus.SUBMIT);
|
|
|
if (CollUtil.isNotEmpty(programmes)) {
|
|
|
this.sort(programmes);
|
|
|
- return this.toShowDTOList(programmes, performance.getName());
|
|
|
+ return this.toShowDTOList(programmes);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
List<Programme> programmes = programmeRepo.findAllByPerformanceIdAndProgrammeStatusAndArrangeIdIsNull(performanceId, ProgrammeStatus.SUBMIT);
|
|
|
if (CollUtil.isNotEmpty(programmes)) {
|
|
|
this.sort(programmes);
|
|
|
- return this.toShowDTOList(programmes, performance.getName());
|
|
|
+ return this.toShowDTOList(programmes);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private List<ProgrammeShowDTO> toShowDTOList(List<Programme> programmes, String name) {
|
|
|
+ public List<ProgrammeShowDTO> toShowDTOList(List<Programme> programmes) {
|
|
|
Map<Long, String> settingMap = settingRepo.findAllByFlagIn(CollUtil.newArrayList(3, 4))
|
|
|
.stream()
|
|
|
.collect(Collectors.toMap(Setting::getId, Setting::getName));
|