|
@@ -1,141 +1,24 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import static com.ym.mec.biz.dal.enums.SignInStatusEnum.NO;
|
|
|
-import static com.ym.mec.biz.dal.enums.SignInStatusEnum.NORMAL;
|
|
|
-import static com.ym.mec.biz.dal.enums.SignInStatusEnum.UNUSUAL;
|
|
|
-import static java.math.BigDecimal.ROUND_DOWN;
|
|
|
-import static java.math.BigDecimal.ZERO;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.time.DayOfWeek;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
-import java.time.ZoneId;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.time.temporal.WeekFields;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import com.ym.mec.biz.dal.enums.*;
|
|
|
-import com.ym.mec.biz.service.*;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Isolation;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
-import com.ym.mec.biz.dal.dao.ClassGroupDao;
|
|
|
-import com.ym.mec.biz.dal.dao.ClassGroupStudentMapperDao;
|
|
|
-import com.ym.mec.biz.dal.dao.ClassGroupTeacherMapperDao;
|
|
|
-import com.ym.mec.biz.dal.dao.ClassGroupTeacherSalaryDao;
|
|
|
-import com.ym.mec.biz.dal.dao.CloudTeacherOrderDao;
|
|
|
-import com.ym.mec.biz.dal.dao.CourseScheduleDao;
|
|
|
-import com.ym.mec.biz.dal.dao.CourseScheduleEvaluateDao;
|
|
|
-import com.ym.mec.biz.dal.dao.CourseScheduleStudentPaymentDao;
|
|
|
-import com.ym.mec.biz.dal.dao.CourseScheduleTeacherSalaryDao;
|
|
|
-import com.ym.mec.biz.dal.dao.EmployeeDao;
|
|
|
-import com.ym.mec.biz.dal.dao.MemberFeeSettingDao;
|
|
|
-import com.ym.mec.biz.dal.dao.MusicGroupDao;
|
|
|
-import com.ym.mec.biz.dal.dao.OrganizationDao;
|
|
|
-import com.ym.mec.biz.dal.dao.PracticeGroupDao;
|
|
|
-import com.ym.mec.biz.dal.dao.PracticeGroupSellPriceDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentAttendanceDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentGoodsSellDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SubjectDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
-import com.ym.mec.biz.dal.dao.TeacherAttendanceDao;
|
|
|
-import com.ym.mec.biz.dal.dao.TeacherDao;
|
|
|
-import com.ym.mec.biz.dal.dao.TeacherDefaultPracticeGroupSalaryDao;
|
|
|
-import com.ym.mec.biz.dal.dao.TeacherFreeTimeDao;
|
|
|
-import com.ym.mec.biz.dal.dao.VipGroupActivityDao;
|
|
|
-import com.ym.mec.biz.dal.dao.VipGroupCategoryDao;
|
|
|
-import com.ym.mec.biz.dal.dao.VipGroupDao;
|
|
|
-import com.ym.mec.biz.dal.dto.BuyDoubleEleven2021Dto;
|
|
|
-import com.ym.mec.biz.dal.dto.CourseScheduleDto;
|
|
|
-import com.ym.mec.biz.dal.dto.ExtendTeacherBasicDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeBuyResultDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeCourseDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeDrillTimeDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeGroupApplyBaseInfoDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeGroupApplyDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeGroupBuyDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeGroupBuyParamsDto;
|
|
|
-import com.ym.mec.biz.dal.dto.PracticeGroupDto;
|
|
|
-import com.ym.mec.biz.dal.dto.SimpleUserDto;
|
|
|
-import com.ym.mec.biz.dal.dto.StudentBuyPracticeDto;
|
|
|
-import com.ym.mec.biz.dal.dto.StudentCourseInfoDto;
|
|
|
-import com.ym.mec.biz.dal.dto.StudentVipGroupDetailDto;
|
|
|
-import com.ym.mec.biz.dal.dto.StudentVipGroupShowListDto;
|
|
|
-import com.ym.mec.biz.dal.dto.TeacherBasicDto;
|
|
|
-import com.ym.mec.biz.dal.dto.VipGroupPayInfoDto;
|
|
|
-import com.ym.mec.biz.dal.dto.VipGroupSalarySettlementDto;
|
|
|
-import com.ym.mec.biz.dal.dto.VipGroupSalarySettlementTypeDto;
|
|
|
-import com.ym.mec.biz.dal.entity.ActivityUserMapper;
|
|
|
-import com.ym.mec.biz.dal.entity.ClassGroup;
|
|
|
-import com.ym.mec.biz.dal.entity.ClassGroupStudentMapper;
|
|
|
-import com.ym.mec.biz.dal.entity.ClassGroupTeacherMapper;
|
|
|
-import com.ym.mec.biz.dal.entity.ClassGroupTeacherSalary;
|
|
|
-import com.ym.mec.biz.dal.entity.CloudTeacherOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.CourseSchedule;
|
|
|
-import com.ym.mec.biz.dal.entity.CourseScheduleEvaluate;
|
|
|
-import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
|
|
|
-import com.ym.mec.biz.dal.entity.CourseScheduleTeacherSalary;
|
|
|
-import com.ym.mec.biz.dal.entity.MemberFeeSetting;
|
|
|
-import com.ym.mec.biz.dal.entity.MusicGroup;
|
|
|
-import com.ym.mec.biz.dal.entity.PracticeGroup;
|
|
|
-import com.ym.mec.biz.dal.entity.PracticeGroupSellPrice;
|
|
|
-import com.ym.mec.biz.dal.entity.Student;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.Subject;
|
|
|
-import com.ym.mec.biz.dal.entity.SysConfig;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
|
|
|
-import com.ym.mec.biz.dal.entity.Teacher;
|
|
|
-import com.ym.mec.biz.dal.entity.TeacherAttendance;
|
|
|
-import com.ym.mec.biz.dal.entity.TeacherDefaultPracticeGroupSalary;
|
|
|
-import com.ym.mec.biz.dal.entity.TeacherFreeTime;
|
|
|
-import com.ym.mec.biz.dal.entity.VipGroup;
|
|
|
-import com.ym.mec.biz.dal.entity.VipGroupActivity;
|
|
|
-import com.ym.mec.biz.dal.entity.VipGroupCategory;
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.dto.*;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.biz.dal.page.PracticeGroupQueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.StudentBuyPracticeQueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.StudentQueryInfo;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.constant.CommonConstants;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
-import com.ym.mec.common.redis.service.RedisCache;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
@@ -143,6 +26,30 @@ import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
import com.ym.mec.util.string.MessageFormatter;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.*;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.WeekFields;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.ym.mec.biz.dal.enums.SignInStatusEnum.*;
|
|
|
+import static java.math.BigDecimal.ROUND_DOWN;
|
|
|
+import static java.math.BigDecimal.ZERO;
|
|
|
|
|
|
@Service
|
|
|
public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGroup> implements PracticeGroupService {
|
|
@@ -4987,6 +4894,309 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResponseResult studentCreateActivityPracticeGroup(PracticeGroupBuyDto practiceGroupBuyParams) {
|
|
|
- return null;
|
|
|
+ SysUser sysUser = Optional.of(sysUserFeignService.queryUserInfo()).orElseThrow(() -> new BizException("请登录"));
|
|
|
+ practiceGroupBuyParams.setStudentId(sysUser.getId());
|
|
|
+ String activeConfig = sysConfigDao.findConfigValue("cloud_teacher_active_config");
|
|
|
+ List<Cloud2022ActivityDto> cloud2022ActivityDtos = JSONArray.parseArray(activeConfig, Cloud2022ActivityDto.class);
|
|
|
+ List<Cloud2022ActivityDto> activityDtos = cloud2022ActivityDtos.stream().filter(e -> e.getOrganId().contains(sysUser.getOrganId().toString())).collect(Collectors.toList());
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isEmpty(activityDtos)){
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "您没有排课资格,请联系指导老师");
|
|
|
+ }
|
|
|
+ //是否还有购买资格
|
|
|
+ Integer activityId = Integer.parseInt(activityDtos.get(0).getActivityId());
|
|
|
+ Integer noCourseNum = activityUserMapperService.getStudentNoCourseNum(sysUser.getId(), activityId);
|
|
|
+ List<ActivityUserMapper> activityUserMappers = activityUserMapperService.findByStudentIdList(activityId, sysUser.getId().toString(), "GIVE_PRACTICE");
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isEmpty(activityUserMappers)){
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "您没有排课资格,请联系指导老师");
|
|
|
+ }
|
|
|
+ if(noCourseNum == null || noCourseNum <= 0){
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "您没有排课资格,请联系指导老师");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getUserId())) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择教师");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getSubjectId())) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择声部");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getAllCourseNum())) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择需要购买的课时数");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getDrillTimesOnWeek())) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择单周陪练次数");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(practiceGroupBuyParams.getDrillTimes())) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择训练时间");
|
|
|
+ }
|
|
|
+ if (practiceGroupBuyParams.getDrillTimesOnWeek() != practiceGroupBuyParams.getDrillTimes().size()) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "训练时间与陪练次数不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
+ Subject subject = subjectDao.get(practiceGroupBuyParams.getSubjectId());
|
|
|
+ if (Objects.isNull(subject)) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "预约失败,声部选择错误,请重试。");
|
|
|
+ }
|
|
|
+
|
|
|
+ Teacher teacher = teacherService.getDetail(practiceGroupBuyParams.getUserId());
|
|
|
+ if (Objects.isNull(teacher)) {
|
|
|
+ throw new BizException("老师不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysConfig practiceCourseMinutesConfig = sysConfigDao.findByParamName(SysConfigService.PRACTICE_COURSE_MINUTES);
|
|
|
+ Integer practiceCourseMinutes = practiceCourseMinutesConfig.getParanValue(Integer.class);
|
|
|
+ SysConfig practiceCourseSalaryConfig = sysConfigDao.findByParamName(SysConfigService.PRACTICE_COURSE_SALARY);
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ LocalDate courseStartDay = LocalDate.now();
|
|
|
+ LocalDate tempCourseLocalDate = LocalDate.parse("2020-03-01", DateUtil.dateFormatter);
|
|
|
+ if (courseStartDay.isBefore(tempCourseLocalDate)) {
|
|
|
+ courseStartDay = tempCourseLocalDate;
|
|
|
+ }
|
|
|
+ if (practiceGroupBuyParams.isRenew()) {
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getGroupId())) {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择需要续费的课程");
|
|
|
+ }
|
|
|
+ PracticeGroup userLatestPracticeGroup = practiceGroupDao.findUserPracticeGroup(practiceGroupBuyParams.getStudentId(), practiceGroupBuyParams.getGroupId());
|
|
|
+ if (Objects.nonNull(userLatestPracticeGroup)) {
|
|
|
+ if (!userLatestPracticeGroup.getGroupStatus().equals(GroupStatusEnum.NORMAL) || userLatestPracticeGroup.getCoursesExpireDate().before(now)) {
|
|
|
+ throw new BizException("当前课程组已经无法续费,请选择购买");
|
|
|
+ }
|
|
|
+ LocalDate lastExpiredDay = LocalDateTime.ofInstant(userLatestPracticeGroup.getCoursesExpireDate().toInstant(), DateUtil.zoneId).toLocalDate();
|
|
|
+ if (Objects.nonNull(lastExpiredDay) && lastExpiredDay.compareTo(courseStartDay) >= 0) {
|
|
|
+ courseStartDay = lastExpiredDay;
|
|
|
+ }
|
|
|
+ practiceGroupBuyParams.setBeRenewGroupId(practiceGroupBuyParams.getGroupId());
|
|
|
+ practiceGroupBuyParams.setEducationalTeacherId(userLatestPracticeGroup.getEducationalTeacherId());
|
|
|
+ } else {
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "需要续费的课程组不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getEducationalTeacherId())) {
|
|
|
+ List<String> musicGroupIds = studentRegistrationDao.queryStudentMusicGroup(practiceGroupBuyParams.getStudentId());
|
|
|
+ if (!CollectionUtils.isEmpty(musicGroupIds) && musicGroupIds.size() <= 1) {
|
|
|
+ MusicGroup musicGroup = musicGroupDao.get(musicGroupIds.get(0));
|
|
|
+ if (Objects.nonNull(musicGroup)) {
|
|
|
+ practiceGroupBuyParams.setEducationalTeacherId(musicGroup.getEducationalTeacherId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ courseStartDay = courseStartDay.plusDays(1);
|
|
|
+ Date courseStartDate = Date.from(courseStartDay.atStartOfDay(DateUtil.zoneId).toInstant());
|
|
|
+ practiceGroupBuyParams.setCoursesStartDate(courseStartDate);
|
|
|
+ LocalDate currentExpiredDay = courseStartDay.plusDays(practiceGroupBuyParams.getBuyMonths());
|
|
|
+ Date courseExpiredDate = Date.from(currentExpiredDay.atStartOfDay(DateUtil.zoneId).toInstant());
|
|
|
+ courseExpiredDate = DateUtil.addSeconds(courseExpiredDate, -1);
|
|
|
+ practiceGroupBuyParams.setCoursesExpireDate(courseExpiredDate);
|
|
|
+
|
|
|
+ LocalDate courseExpiredSunday = currentExpiredDay.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
|
|
|
+ Date courseExpiredSundayDate = Date.from(courseExpiredSunday.atStartOfDay(DateUtil.zoneId).toInstant());
|
|
|
+
|
|
|
+ practiceGroupBuyParams.setName(subject.getName() + "•" + sysUser.getUsername());
|
|
|
+ List<CourseSchedule> practiceCourses = createPracticeCourses(practiceGroupBuyParams, practiceCourseMinutes);
|
|
|
+ practiceCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
+
|
|
|
+ LocalDate classStartDate = LocalDateTime.ofInstant(practiceCourses.get(0).getClassDate().toInstant(), DateUtil.zoneId).toLocalDate();
|
|
|
+ LocalDate courseStartMonday = classStartDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
|
|
|
+ Date courseStartMondayDate = Date.from(courseStartMonday.atStartOfDay(DateUtil.zoneId).toInstant());
|
|
|
+
|
|
|
+ List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(practiceGroupBuyParams.getUserId(), courseStartMondayDate, courseExpiredSundayDate);
|
|
|
+
|
|
|
+ TeacherFreeTime teacherFreeTime = teacherFreeTimeDao.findTeacherFreeTime(practiceGroupBuyParams.getUserId());
|
|
|
+ Integer maxTeacherCourses = null;
|
|
|
+ if (Objects.nonNull(teacherFreeTime)) {
|
|
|
+ if (Objects.nonNull(teacherFreeTime.getTotalTimes())) {
|
|
|
+ maxTeacherCourses = teacherFreeTime.getTotalTimes();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return BaseController.failed(HttpStatus.MULTIPLE_CHOICES, "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
|
|
|
+ }
|
|
|
+
|
|
|
+ int courseWeekNum = 0;
|
|
|
+ int practiceCourseNum = 0;
|
|
|
+ LocalDateTime tempClassDateTime;
|
|
|
+ for (int i = 0; i < allTeacherCourses.size(); i++) {
|
|
|
+ CourseSchedule teacherCourse = allTeacherCourses.get(i);
|
|
|
+ tempClassDateTime = LocalDateTime.ofInstant(teacherCourse.getClassDate().toInstant(), DateUtil.zoneId);
|
|
|
+ if (i == 0 && teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
|
|
|
+ practiceCourseNum += 1;
|
|
|
+ courseWeekNum = tempClassDateTime.get(DateUtil.weekFields.weekOfYear());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(maxTeacherCourses) && practiceCourseNum >= maxTeacherCourses) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return BaseController.failed(HttpStatus.MULTIPLE_CHOICES, "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
|
|
|
+ }
|
|
|
+ if (tempClassDateTime.get(DateUtil.weekFields.weekOfYear()) != courseWeekNum) {
|
|
|
+ courseWeekNum = tempClassDateTime.get(DateUtil.weekFields.weekOfYear());
|
|
|
+ practiceCourseNum = 0;
|
|
|
+ }
|
|
|
+ if (teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
|
|
|
+ practiceCourseNum += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ allTeacherCourses = new ArrayList<>();
|
|
|
+
|
|
|
+ JSONObject drillTimesObject = new JSONObject();
|
|
|
+ for (PracticeDrillTimeDto drillTime : practiceGroupBuyParams.getDrillTimes()) {
|
|
|
+ drillTimesObject.put(String.valueOf(drillTime.getWeekNum()), drillTime.getTimeStr());
|
|
|
+ }
|
|
|
+
|
|
|
+ PracticeGroupSellPrice practiceGroupSellPrice = practiceGroupSellPriceDao.get(sysUser.getOrganId());
|
|
|
+ if (Objects.isNull(practiceGroupSellPrice)) {
|
|
|
+ throw new BizException("该分部未设置网管课价格");
|
|
|
+ }
|
|
|
+ BigDecimal oneMonthPrice = practiceGroupSellPrice.getSingleClassMinutesPrice();
|
|
|
+ practiceGroupBuyParams.setDrillTimesJson(drillTimesObject.toJSONString());
|
|
|
+ practiceGroupBuyParams.setOrganId(sysUser.getOrganId());
|
|
|
+ practiceGroupBuyParams.setSingleClassMinutes(practiceCourseMinutes);
|
|
|
+ practiceGroupBuyParams.setGroupStatus(GroupStatusEnum.NORMAL);
|
|
|
+ practiceGroupBuyParams.setType(PracticeGroupType.CHARGE);
|
|
|
+ practiceGroupBuyParams.setMemo("小小训练营活动排课");
|
|
|
+ practiceGroupDao.insert(practiceGroupBuyParams);
|
|
|
+
|
|
|
+ //创建班级信息
|
|
|
+ ClassGroup classGroup = new ClassGroup();
|
|
|
+ classGroup.setSubjectIdList(practiceGroupBuyParams.getSubjectId().toString());
|
|
|
+ classGroup.setExpectStudentNum(1);
|
|
|
+ classGroup.setStudentNum(1);
|
|
|
+ classGroup.setName(practiceGroupBuyParams.getName());
|
|
|
+ classGroup.setTotalClassTimes(practiceCourses.size());
|
|
|
+ classGroup.setType(ClassGroupTypeEnum.PRACTICE);
|
|
|
+ classGroup.setDelFlag(0);
|
|
|
+ classGroup.setGroupType(GroupType.PRACTICE);
|
|
|
+ classGroup.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ classGroup.setCreateTime(now);
|
|
|
+ classGroup.setUpdateTime(now);
|
|
|
+ classGroupDao.insert(classGroup);
|
|
|
+
|
|
|
+ //创建班级老师关联记录
|
|
|
+ ClassGroupTeacherMapper classGroupTeacherMapper = new ClassGroupTeacherMapper();
|
|
|
+ classGroupTeacherMapper.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ classGroupTeacherMapper.setClassGroupId(classGroup.getId());
|
|
|
+ classGroupTeacherMapper.setTeacherRole(TeachTypeEnum.BISHOP);
|
|
|
+ classGroupTeacherMapper.setUserId(practiceGroupBuyParams.getUserId());
|
|
|
+ classGroupTeacherMapper.setGroupType(GroupType.PRACTICE);
|
|
|
+ classGroupTeacherMapper.setCreateTime(now);
|
|
|
+ classGroupTeacherMapper.setUpdateTime(now);
|
|
|
+ classGroupTeacherMapperDao.insert(classGroupTeacherMapper);
|
|
|
+
|
|
|
+ //创建班级与老师课酬记录
|
|
|
+ ClassGroupTeacherSalary classGroupTeacherSalary = new ClassGroupTeacherSalary();
|
|
|
+ classGroupTeacherSalary.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ classGroupTeacherSalary.setClassGroupId(classGroup.getId());
|
|
|
+ classGroupTeacherSalary.setTeacherRole(TeachTypeEnum.BISHOP);
|
|
|
+ classGroupTeacherSalary.setUserId(practiceGroupBuyParams.getUserId());
|
|
|
+ classGroupTeacherSalary.setSalary(new BigDecimal(practiceCourseSalaryConfig.getParanValue()));
|
|
|
+ classGroupTeacherSalary.setOnlineClassesSalary(new BigDecimal(practiceCourseSalaryConfig.getParanValue()));
|
|
|
+ classGroupTeacherSalary.setGroupType(GroupType.PRACTICE);
|
|
|
+ classGroupTeacherSalary.setCreateTime(now);
|
|
|
+ classGroupTeacherSalary.setUpdateTime(now);
|
|
|
+ classGroupTeacherSalaryDao.insert(classGroupTeacherSalary);
|
|
|
+
|
|
|
+ //班级学生关联表
|
|
|
+ ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
|
|
|
+ classGroupStudentMapper.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ classGroupStudentMapper.setClassGroupId(classGroup.getId());
|
|
|
+ classGroupStudentMapper.setUserId(practiceGroupBuyParams.getStudentId());
|
|
|
+ classGroupStudentMapper.setCreateTime(now);
|
|
|
+ classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
|
|
|
+ classGroupStudentMapper.setGroupType(GroupType.PRACTICE);
|
|
|
+ classGroupStudentMapperDao.insert(classGroupStudentMapper);
|
|
|
+
|
|
|
+ List<CourseScheduleTeacherSalary> courseScheduleTeacherSalaries = new ArrayList<>();
|
|
|
+ List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
|
|
|
+ List<TeacherAttendance> teacherAttendances = new ArrayList<>();
|
|
|
+
|
|
|
+ for (CourseSchedule courseSchedule : practiceCourses) {
|
|
|
+ //课表
|
|
|
+ courseSchedule.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ courseSchedule.setClassGroupId(classGroup.getId());
|
|
|
+ courseSchedule.setStatus(CourseStatusEnum.NOT_START);
|
|
|
+ courseSchedule.setCreateTime(now);
|
|
|
+ courseSchedule.setUpdateTime(now);
|
|
|
+ courseSchedule.setTeachMode(TeachModeEnum.ONLINE);
|
|
|
+ courseSchedule.setType(CourseSchedule.CourseScheduleType.PRACTICE);
|
|
|
+ courseSchedule.setGroupType(GroupType.PRACTICE);
|
|
|
+ courseSchedule.setIsLock(0);
|
|
|
+ courseSchedule.setOrganId(practiceGroupBuyParams.getOrganId());
|
|
|
+ }
|
|
|
+ courseScheduleDao.batchAddCourseSchedules(practiceCourses);
|
|
|
+ TeacherDefaultPracticeGroupSalary teacherDefaultPracticeGroupSalary = teacherDefaultPracticeGroupSalaryDao.findByTeacherAndCourseMinutes(practiceGroupBuyParams.getUserId(), practiceCourseMinutes);
|
|
|
+ BigDecimal teacherDefaultSalary = null;
|
|
|
+ if (Objects.nonNull(teacherDefaultPracticeGroupSalary)) {
|
|
|
+ teacherDefaultSalary = teacherDefaultPracticeGroupSalary.getMainTeacherSalary();
|
|
|
+ }
|
|
|
+ if (teacherDefaultSalary == null) {
|
|
|
+ throw new BizException("请设置教师课酬");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal actualPrice = activityUserMappers.get(0).getActualPrice();
|
|
|
+ BigDecimal divide = actualPrice.divide(new BigDecimal(practiceCourses.size()), ROUND_DOWN);
|
|
|
+ BigDecimal firstAmount = actualPrice.subtract(divide.multiply(new BigDecimal(practiceCourses.size()))).add(divide);
|
|
|
+ for (int i = 0; i < practiceCourses.size(); i++) {
|
|
|
+ CourseSchedule courseSchedule = practiceCourses.get(i);
|
|
|
+ //课程与老师薪水表
|
|
|
+ CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
|
|
|
+ courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ courseScheduleTeacherSalary.setGroupType(GroupType.PRACTICE);
|
|
|
+ courseScheduleTeacherSalary.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ courseScheduleTeacherSalary.setTeacherRole(classGroupTeacherMapper.getTeacherRole());
|
|
|
+ courseScheduleTeacherSalary.setUserId(practiceGroupBuyParams.getUserId());
|
|
|
+ courseScheduleTeacherSalary.setExpectSalary(teacherDefaultSalary);
|
|
|
+ courseScheduleTeacherSalary.setCreateTime(now);
|
|
|
+ courseScheduleTeacherSalary.setUpdateTime(now);
|
|
|
+ courseScheduleTeacherSalary.setClassGroupId(classGroup.getId());
|
|
|
+ courseScheduleTeacherSalaries.add(courseScheduleTeacherSalary);
|
|
|
+
|
|
|
+ //学生缴费记录
|
|
|
+ CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
|
|
|
+ courseScheduleStudentPayment.setGroupType(GroupType.PRACTICE);
|
|
|
+ courseScheduleStudentPayment.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ courseScheduleStudentPayment.setUserId(practiceGroupBuyParams.getStudentId());
|
|
|
+ if (i == 0) {
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(firstAmount);
|
|
|
+ courseScheduleStudentPayment.setActualPrice(firstAmount);
|
|
|
+ } else {
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(divide);
|
|
|
+ courseScheduleStudentPayment.setActualPrice(divide);
|
|
|
+ }
|
|
|
+ courseScheduleStudentPayment.setOriginalPrice(oneMonthPrice);
|
|
|
+ courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
|
|
|
+ courseScheduleStudentPayment.setCreateTime(now);
|
|
|
+ courseScheduleStudentPayment.setUpdateTime(now);
|
|
|
+ courseScheduleStudentPayments.add(courseScheduleStudentPayment);
|
|
|
+
|
|
|
+ //教师签到记录
|
|
|
+ TeacherAttendance teacherAttendance = new TeacherAttendance();
|
|
|
+ teacherAttendance.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ teacherAttendance.setTeacherId(practiceGroupBuyParams.getUserId());
|
|
|
+ teacherAttendance.setClassGroupId(classGroup.getId());
|
|
|
+ teacherAttendance.setGroupType(GroupType.PRACTICE);
|
|
|
+ teacherAttendance.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ teacherAttendance.setCreateTime(now);
|
|
|
+ teacherAttendances.add(teacherAttendance);
|
|
|
+ }
|
|
|
+ courseScheduleTeacherSalaryDao.batchInsert(courseScheduleTeacherSalaries);
|
|
|
+ courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
|
|
|
+ teacherAttendanceDao.batchInsert(teacherAttendances);
|
|
|
+
|
|
|
+ try {
|
|
|
+ courseScheduleService.checkNewCourseSchedules(practiceCourses, false, false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ String errMessage = new String();
|
|
|
+ if (e.getMessage().indexOf("主教冲突") != -1) {
|
|
|
+ errMessage = "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。";
|
|
|
+ } else {
|
|
|
+ String courseName = e.getMessage().substring(e.getMessage().indexOf(")-") + 2);
|
|
|
+ courseName = courseName.substring(0, courseName.indexOf("("));
|
|
|
+ errMessage = "抱歉啦,当前所选时段组合,与您现有课程「";
|
|
|
+ errMessage += courseName;
|
|
|
+ errMessage += "」时段冲突,请选择其他时段重试。";
|
|
|
+ }
|
|
|
+ return BaseController.failed(HttpStatus.FOUND, errMessage);
|
|
|
+ }
|
|
|
+ return BaseController.succeed();
|
|
|
}
|
|
|
}
|