|
|
@@ -1,11 +1,14 @@
|
|
|
package com.izouma.wenlvju.service;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.izouma.wenlvju.domain.ArtType;
|
|
|
+import com.izouma.wenlvju.domain.Organization;
|
|
|
import com.izouma.wenlvju.domain.Performance;
|
|
|
import com.izouma.wenlvju.domain.PerformanceApply;
|
|
|
import com.izouma.wenlvju.dto.PageQuery;
|
|
|
import com.izouma.wenlvju.enums.ApplyStatus;
|
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
|
+import com.izouma.wenlvju.repo.ArtTypeRepo;
|
|
|
+import com.izouma.wenlvju.repo.OrganizationRepo;
|
|
|
import com.izouma.wenlvju.repo.PerformanceApplyRepo;
|
|
|
import com.izouma.wenlvju.repo.PerformanceRepo;
|
|
|
import com.izouma.wenlvju.utils.JpaUtils;
|
|
|
@@ -13,20 +16,47 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class PerformanceApplyService {
|
|
|
|
|
|
- private PerformanceApplyRepo performanceApplyRepo;
|
|
|
- private PerformanceRepo performanceRepo;
|
|
|
+ private final PerformanceApplyRepo performanceApplyRepo;
|
|
|
+ private final PerformanceRepo performanceRepo;
|
|
|
+ private final ArtTypeRepo artTypeRepo;
|
|
|
+ private final OrganizationRepo organizationRepo;
|
|
|
|
|
|
public Page<PerformanceApply> all(PageQuery pageQuery) {
|
|
|
- return performanceApplyRepo.findAll(JpaUtils.toSpecification(pageQuery, PerformanceApply.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ Page<PerformanceApply> all = performanceApplyRepo.findAll(JpaUtils.toSpecification(pageQuery, PerformanceApply.class), JpaUtils
|
|
|
+ .toPageRequest(pageQuery));
|
|
|
+ Set<Long> artTypeId = new HashSet<>();
|
|
|
+ Set<Long> organizationId = new HashSet<>();
|
|
|
+ all.forEach(apply -> {
|
|
|
+ artTypeId.add(apply.getArtTypeId());
|
|
|
+ organizationId.add(apply.getOrganizationId());
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<Long, String> artMap = artTypeRepo.findAllById(artTypeId)
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ArtType::getId, ArtType::getName));
|
|
|
+ Map<Long, String> organzationMap = organizationRepo.findAllById(organizationId)
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(Organization::getId, Organization::getName));
|
|
|
+
|
|
|
+ return all.map(apply -> {
|
|
|
+ apply.setArtType(artMap.get(apply.getArtTypeId()));
|
|
|
+ apply.setOrganizer(organzationMap.get(apply.getOrganizationId()));
|
|
|
+ return apply;
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void audit(Long id, Boolean pass) {
|
|
|
@@ -42,53 +72,102 @@ public class PerformanceApplyService {
|
|
|
/*
|
|
|
自动编排
|
|
|
*/
|
|
|
- public void autoArrangement(Long performanceId) {
|
|
|
- List<PerformanceApply> applyList =
|
|
|
- performanceApplyRepo.findAllByStatusAndPerformanceId(ApplyStatus.PASS, performanceId);
|
|
|
+// public void autoArrangement(Long performanceId) {
|
|
|
+// List<PerformanceApply> applyList =
|
|
|
+// performanceApplyRepo.findAllByStatusAndPerformanceId(ApplyStatus.PASS, performanceId);
|
|
|
+//
|
|
|
+// List<PerformanceApply> showTime = applyList.stream()
|
|
|
+// .filter(apply -> apply.getShowTime() != null)
|
|
|
+// .sorted((a, b) -> b.getShowTime().compareTo(a.getShowTime()))
|
|
|
+// .collect(Collectors.toList());
|
|
|
+// List<PerformanceApply> showTimeNull = applyList.stream()
|
|
|
+// .filter(apply -> apply.getShowTime() == null)
|
|
|
+// .collect(Collectors.toList());
|
|
|
+//
|
|
|
+// if (CollUtil.isEmpty(showTimeNull)) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (CollUtil.isEmpty(showTime)) {
|
|
|
+// Performance performance = performanceRepo.findById(performanceId).orElseThrow(new BusinessException("无记录"));
|
|
|
+// final LocalDateTime[] time = {LocalDateTime.of(performance.getStartTime().plusDays(3), LocalTime.now())};
|
|
|
+// showTimeNull.forEach(apply -> {
|
|
|
+// apply.setShowTime(time[0]);
|
|
|
+// performanceApplyRepo.save(apply);
|
|
|
+// time[0] = time[0].plusMinutes(10);
|
|
|
+// });
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// final LocalDateTime[] time = {showTime.get(0).getShowTime().plusMinutes(10)};
|
|
|
+// showTimeNull.forEach(apply -> {
|
|
|
+// apply.setShowTime(time[0]);
|
|
|
+// performanceApplyRepo.save(apply);
|
|
|
+// time[0] = time[0].plusMinutes(10);
|
|
|
+// });
|
|
|
+// }
|
|
|
|
|
|
- List<PerformanceApply> showTime = applyList.stream()
|
|
|
- .filter(apply -> apply.getShowTime() != null)
|
|
|
- .sorted((a, b) -> b.getShowTime().compareTo(a.getShowTime()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<PerformanceApply> showTimeNull = applyList.stream()
|
|
|
- .filter(apply -> apply.getShowTime() == null)
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
- if (CollUtil.isEmpty(showTimeNull)) {
|
|
|
- return;
|
|
|
+ public List<PerformanceApply> autoArrangement1(Long performanceId) {
|
|
|
+ Performance performance = performanceRepo.findById(performanceId).orElseThrow(new BusinessException("无记录"));
|
|
|
+ if (LocalDate.now().isBefore(performance.getEndDate())) {
|
|
|
+ throw new BusinessException("报名结束后才可以自动编排");
|
|
|
}
|
|
|
|
|
|
- if (CollUtil.isEmpty(showTime)) {
|
|
|
- Performance performance = performanceRepo.findById(performanceId).orElseThrow(new BusinessException("无记录"));
|
|
|
- final LocalDateTime[] time = {LocalDateTime.of(performance.getStartTime().plusDays(3), LocalTime.now())};
|
|
|
- showTimeNull.forEach(apply -> {
|
|
|
- apply.setShowTime(time[0]);
|
|
|
- performanceApplyRepo.save(apply);
|
|
|
- time[0] = time[0].plusMinutes(10);
|
|
|
- });
|
|
|
- return;
|
|
|
+ List<PerformanceApply> applyList =
|
|
|
+ performanceApplyRepo.findAllByStatusAndPerformanceId(ApplyStatus.PASS, performanceId);
|
|
|
+ LocalDate startDate = performance.getEventStartDate();
|
|
|
+// LocalDate endDate = performance.getEndDate();
|
|
|
+ LocalTime dayStart = performance.getMorningStartTime();
|
|
|
+ LocalTime dayEnd = performance.getMorningEndTime();
|
|
|
+// Long length = performance.getProgrammeLength();
|
|
|
+
|
|
|
+ LocalTime dayChange = dayStart;
|
|
|
+ for (PerformanceApply apply : applyList) {
|
|
|
+// if (start.isAfter(endDate)) {
|
|
|
+// throw new BusinessException("展示时间过短,请编辑展演结束时间。");
|
|
|
+// }
|
|
|
+ if (dayChange.isAfter(dayEnd)) {
|
|
|
+ dayChange = performance.getAfternoonStartTime();
|
|
|
+ }
|
|
|
+ apply.setShowStartTime(LocalDateTime.of(startDate, dayChange));
|
|
|
+ dayChange = dayChange.plusMinutes(30);
|
|
|
+ apply.setShowEndTime(LocalDateTime.of(startDate, dayChange));
|
|
|
}
|
|
|
- final LocalDateTime[] time = {showTime.get(0).getShowTime().plusMinutes(10)};
|
|
|
- showTimeNull.forEach(apply -> {
|
|
|
- apply.setShowTime(time[0]);
|
|
|
- performanceApplyRepo.save(apply);
|
|
|
- time[0] = time[0].plusMinutes(10);
|
|
|
+
|
|
|
+
|
|
|
+ Set<Long> artTypeId = new HashSet<>();
|
|
|
+ Set<Long> organizationId = new HashSet<>();
|
|
|
+ applyList.forEach(apply -> {
|
|
|
+ artTypeId.add(apply.getArtTypeId());
|
|
|
+ organizationId.add(apply.getOrganizationId());
|
|
|
});
|
|
|
+
|
|
|
+ Map<Long, String> artMap = artTypeRepo.findAllById(artTypeId)
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ArtType::getId, ArtType::getName));
|
|
|
+ Map<Long, String> organzationMap = organizationRepo.findAllById(organizationId)
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(Organization::getId, Organization::getName));
|
|
|
+ applyList.forEach(apply -> {
|
|
|
+ apply.setArtType(artMap.get(apply.getArtTypeId()));
|
|
|
+ apply.setOrganizer(organzationMap.get(apply.getOrganizationId()));
|
|
|
+ });
|
|
|
+ return applyList;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
自动评奖
|
|
|
*/
|
|
|
public void autoAwards(Long performanceId) {
|
|
|
- List<PerformanceApply> applies = performanceApplyRepo.findAllByShowTimeIsNotNullAndPerformanceId(performanceId);
|
|
|
- if (CollUtil.isEmpty(applies)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- applies.forEach(apply -> {
|
|
|
- apply.setAwards("一等奖");
|
|
|
- apply.setScore(100);
|
|
|
- performanceApplyRepo.save(apply);
|
|
|
- });
|
|
|
+// List<PerformanceApply> applies = performanceApplyRepo.findAllByShowTimeIsNotNullAndPerformanceId(performanceId);
|
|
|
+// if (CollUtil.isEmpty(applies)) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// applies.forEach(apply -> {
|
|
|
+// apply.setAwards("一等奖");
|
|
|
+// apply.setScore(100);
|
|
|
+// performanceApplyRepo.save(apply);
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
}
|