|
|
@@ -3,17 +3,15 @@ package com.izouma.wenlvju.service;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-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.domain.*;
|
|
|
import com.izouma.wenlvju.dto.PageQuery;
|
|
|
import com.izouma.wenlvju.enums.ApplyStatus;
|
|
|
+import com.izouma.wenlvju.enums.AuthorityName;
|
|
|
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.repo.*;
|
|
|
+import com.izouma.wenlvju.security.Authority;
|
|
|
+import com.izouma.wenlvju.security.JwtTokenUtil;
|
|
|
+import com.izouma.wenlvju.security.JwtUserFactory;
|
|
|
import com.izouma.wenlvju.utils.JpaUtils;
|
|
|
import com.izouma.wenlvju.utils.ObjUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -23,10 +21,7 @@ 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.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -37,6 +32,10 @@ public class PerformanceApplyService {
|
|
|
private final PerformanceRepo performanceRepo;
|
|
|
private final ArtTypeRepo artTypeRepo;
|
|
|
private final OrganizationRepo organizationRepo;
|
|
|
+ private final PersonRepo personRepo;
|
|
|
+ private final UserRepo userRepo;
|
|
|
+ private final JwtTokenUtil jwtTokenUtil;
|
|
|
+ private final PerformanceScoreRepo performanceScoreRepo;
|
|
|
|
|
|
public Page<PerformanceApply> all(PageQuery pageQuery) {
|
|
|
Page<PerformanceApply> all = performanceApplyRepo.findAll(JpaUtils.toSpecification(pageQuery, PerformanceApply.class), JpaUtils
|
|
|
@@ -73,50 +72,13 @@ public class PerformanceApplyService {
|
|
|
performanceApplyRepo.save(apply);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- 自动编排
|
|
|
- */
|
|
|
-// 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);
|
|
|
-// });
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
public List<PerformanceApply> autoArrangement1(Long performanceId) {
|
|
|
Performance performance = performanceRepo.findById(performanceId).orElseThrow(new BusinessException("无记录"));
|
|
|
if (LocalDate.now().isBefore(performance.getEndDate())) {
|
|
|
throw new BusinessException("报名结束后才可以自动编排");
|
|
|
}
|
|
|
|
|
|
+ // 只编排通过的
|
|
|
List<PerformanceApply> applyList =
|
|
|
performanceApplyRepo.findAllByStatusAndPerformanceId(ApplyStatus.PASS, performanceId);
|
|
|
LocalDate startDate = performance.getEventStartDate();
|
|
|
@@ -194,4 +156,90 @@ public class PerformanceApplyService {
|
|
|
// });
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 签到
|
|
|
+ 由管理人员先登陆,进行签到
|
|
|
+ */
|
|
|
+ public PerformanceApply signIn(Long id, Long userId) {
|
|
|
+ PerformanceApply performanceApply = performanceApplyRepo.findById(id)
|
|
|
+ .orElseThrow(new BusinessException("无此表演"));
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotNull(performanceApply.getSignInAt()) && ObjectUtil.isNotNull(performanceApply.getSignInBy())) {
|
|
|
+ throw new BusinessException("已签到");
|
|
|
+ }
|
|
|
+
|
|
|
+ performanceApply.setSignInAt(LocalDateTime.now());
|
|
|
+ performanceApply.setSignInBy(userId);
|
|
|
+
|
|
|
+ return performanceApplyRepo.save(performanceApply);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 扫描作品二维码,通过手机号获取身份
|
|
|
+ */
|
|
|
+ public Map<String, String> getAuth(Long id, String phone) {
|
|
|
+ PerformanceApply performanceApply = performanceApplyRepo.findById(id)
|
|
|
+ .orElseThrow(new BusinessException("无此表演"));
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+
|
|
|
+ if (phone.equals(performanceApply.getPhone())) {
|
|
|
+ map.put("phone", phone);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> phones = personRepo.findAllByPerformanceApplyId(id)
|
|
|
+ .stream()
|
|
|
+ .map(Person::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (phones.contains(phone)) {
|
|
|
+ map.put("phone", phone);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userRepo.findByPhoneAndDelFalse(phone);
|
|
|
+ if (ObjectUtil.isNull(user)) {
|
|
|
+ throw new BusinessException("手机号错误");
|
|
|
+ }
|
|
|
+ if (!user.getAuthorities().contains(Authority.get(AuthorityName.ROLE_ADMIN))) {
|
|
|
+ throw new BusinessException("无权限");
|
|
|
+ }
|
|
|
+ String token = jwtTokenUtil.generateToken(JwtUserFactory.create(user));
|
|
|
+ map.put("phone", phone);
|
|
|
+ map.put("token", token);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 评分
|
|
|
+ */
|
|
|
+ public void score(Long id, double score, Long userId) {
|
|
|
+ PerformanceApply apply = performanceApplyRepo.findById(id).orElseThrow(new BusinessException("无此表演"));
|
|
|
+ if (!ApplyStatus.PASS.equals(apply.getStatus())) {
|
|
|
+ throw new BusinessException("此节目未通过审核");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNull(apply.getShowStartTime())) {
|
|
|
+ throw new BusinessException("无表演时间");
|
|
|
+ }
|
|
|
+ if (LocalDateTime.now().isBefore(apply.getShowStartTime())) {
|
|
|
+ throw new BusinessException("节目暂未开始");
|
|
|
+ }
|
|
|
+
|
|
|
+ PerformanceScore performanceScore = PerformanceScore.builder()
|
|
|
+ .performanceApplyId(id)
|
|
|
+ .score(score)
|
|
|
+ .userId(userId)
|
|
|
+ .build();
|
|
|
+ performanceScoreRepo.save(performanceScore);
|
|
|
+
|
|
|
+ double scores = performanceScoreRepo.findAllByPerformanceApplyId(id)
|
|
|
+ .stream()
|
|
|
+ .mapToDouble(PerformanceScore::getScore)
|
|
|
+ .average()
|
|
|
+ .orElse(0.0);
|
|
|
+
|
|
|
+// double scores1 = (double) Math.round(scores * 1000) / 1000;
|
|
|
+ apply.setScore(scores);
|
|
|
+ performanceApplyRepo.save(apply);
|
|
|
+ }
|
|
|
}
|