|
@@ -3204,6 +3204,419 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public HttpResponseResult createPackagePracticeGroup(PracticeGroupBuyDto practiceGroupBuyParams) {
|
|
|
+ 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.getBuyMonths())) {
|
|
|
+ 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, "训练时间与陪练次数不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserById(practiceGroupBuyParams.getStudentId());
|
|
|
+
|
|
|
+ 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 = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_MINUTES);
|
|
|
+ Integer practiceCourseMinutes = practiceCourseMinutesConfig.getParanValue(Integer.class);
|
|
|
+ SysConfig practiceCourseSalaryConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_SALARY);
|
|
|
+ SysConfig practiceBuyActivityExpireDateConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_BUY_ACTIVITY_EXPIRE_DATE);
|
|
|
+ SysConfig practicePromotionActivityStartDateConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_PROMOTION_ACTIVITY_START_DATE);
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ LocalDate courseStartDay = LocalDate.now();
|
|
|
+ LocalDate tempCourseLocalDate = LocalDate.parse("2020-03-01", DateUtil.dateFormatter);
|
|
|
+ if (courseStartDay.isBefore(tempCourseLocalDate)) {
|
|
|
+ courseStartDay = tempCourseLocalDate;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.plusMonths(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);
|
|
|
+
|
|
|
+ Student student = studentDao.get(practiceGroupBuyParams.getStudentId());
|
|
|
+ List<PracticeGroup> userStatusPracticeGroups = practiceGroupDao.findUserStatusPracticeGroups(practiceGroupBuyParams.getStudentId(), null, PracticeGroupType.COME_ON_PACKAGE);
|
|
|
+ long normalGroupNum = userStatusPracticeGroups.stream().filter(p -> GroupStatusEnum.LOCK.equals(p.getGroupStatus()) || GroupStatusEnum.NORMAL.equals(p.getGroupStatus())).count();
|
|
|
+ if(Objects.isNull(student.getComeOnPackage())||student.getComeOnPackage().equals(0)){
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "该学员暂无加油包排课资格");
|
|
|
+ }else if(student.getComeOnPackage().equals(2)||normalGroupNum>0){
|
|
|
+ return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "该学员已使用加油包排课资格");
|
|
|
+ }
|
|
|
+ Integer courseTimes = 8;
|
|
|
+
|
|
|
+ while (practiceCourses.size()<courseTimes) {
|
|
|
+ courseStartDay=courseStartDay.plusDays(1);
|
|
|
+ int dayOfWeek = courseStartDay.get(DateUtil.weekFields.dayOfWeek());
|
|
|
+ for (PracticeDrillTimeDto drillTime : practiceGroupBuyParams.getDrillTimes()) {
|
|
|
+ if(practiceCourses.size()==courseTimes){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(dayOfWeek==drillTime.getWeekNum()){
|
|
|
+ CourseSchedule courseSchedule=new CourseSchedule();
|
|
|
+ String courseStartDayStr = DateUtil.dateFormatter.format(courseStartDay);
|
|
|
+ String courseStartDateTimeStr = courseStartDayStr+" "+drillTime.getTimeStr();
|
|
|
+ LocalDateTime courseStartDateTime = LocalDateTime.parse(courseStartDateTimeStr,DateUtil.dateTimeFormatter);
|
|
|
+ LocalDateTime courseEndDateTime = courseStartDateTime.plusMinutes(practiceCourseMinutes);
|
|
|
+ courseSchedule.setStartClassTime(Date.from(courseStartDateTime.atZone(DateUtil.zoneId).toInstant()));
|
|
|
+ courseSchedule.setEndClassTime(Date.from(courseEndDateTime.atZone(DateUtil.zoneId).toInstant()));
|
|
|
+ courseSchedule.setClassDate(courseSchedule.getStartClassTime());
|
|
|
+ courseSchedule.setName(practiceGroupBuyParams.getName());
|
|
|
+ courseSchedule.setTeacherId(practiceGroupBuyParams.getUserId());
|
|
|
+ courseSchedule.setActualTeacherId(practiceGroupBuyParams.getUserId());
|
|
|
+ courseSchedule.setTeachMode(TeachModeEnum.ONLINE);
|
|
|
+ courseSchedule.setType(CourseSchedule.CourseScheduleType.PRACTICE);
|
|
|
+ courseSchedule.setStatus(CourseStatusEnum.NOT_START);
|
|
|
+ practiceCourses.add(courseSchedule);
|
|
|
+
|
|
|
+ if(practiceCourses.size()==courseTimes){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ CourseSchedule courseSchedule1=new CourseSchedule();
|
|
|
+ BeanUtils.copyProperties(courseSchedule, courseSchedule1);
|
|
|
+ courseSchedule1.setStartClassTime(courseSchedule.getEndClassTime());
|
|
|
+ courseSchedule1.setEndClassTime(Date.from(courseEndDateTime.plusMinutes(practiceCourseMinutes).atZone(DateUtil.zoneId).toInstant()));
|
|
|
+ courseSchedule1.setClassDate(courseSchedule1.getStartClassTime());
|
|
|
+ practiceCourses.add(courseSchedule1);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 amount = PracticeGroupType.CARE_PACKAGE.equals(practiceGroupBuyParams.getType())?practiceGroupSellPrice.getCarePackagePrice():practiceGroupSellPrice.getComeOnPackagePrice();
|
|
|
+ if(Objects.isNull(amount)&&PracticeGroupType.COME_ON_PACKAGE.equals(practiceGroupBuyParams.getType())){
|
|
|
+ throw new BizException("请设置加油包价格");
|
|
|
+ }
|
|
|
+
|
|
|
+ practiceGroupBuyParams.setDrillTimesJson(drillTimesObject.toJSONString());
|
|
|
+ practiceGroupBuyParams.setOrganId(sysUser.getOrganId());
|
|
|
+ practiceGroupBuyParams.setSingleClassMinutes(practiceCourseMinutes);
|
|
|
+ practiceGroupBuyParams.setGroupStatus(GroupStatusEnum.LOCK);
|
|
|
+ practiceGroupBuyParams.setType(PracticeGroupType.COME_ON_PACKAGE);
|
|
|
+ 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(1);
|
|
|
+ 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 studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ BigDecimal oneMonthOriginalPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceOriginalPrice():practiceGroupSellPrice.getTwiceOriginalPrice();
|
|
|
+ BigDecimal originalAmount = oneMonthOriginalPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
|
|
|
+ BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ for (CourseSchedule courseSchedule : practiceCourses) {
|
|
|
+ //课程与老师薪水表
|
|
|
+ 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());
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(studentSingleCourseCost);
|
|
|
+ courseScheduleStudentPayment.setActualPrice(studentSingleCourseCost);
|
|
|
+ courseScheduleStudentPayment.setOriginalPrice(studentSingleCourseOriginalCost);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ studentPaymentOrder.setUserId(practiceGroupBuyParams.getStudentId());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.PRACTICE);
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
|
|
|
+ if (practiceGroupBuyParams.isRenew()) {
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_RENEW);
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
+ studentPaymentOrder.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount());
|
|
|
+ studentPaymentOrder.setClassGroupId(classGroup.getId());
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
+
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
+ if (practiceGroupBuyParams.isUseBalancePayment() || studentPaymentOrder.getExpectAmount().doubleValue() == 0) {
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(practiceGroupBuyParams.getStudentId());
|
|
|
+ if (userCashAccount == null) {
|
|
|
+ throw new BizException("用户账户找不到");
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
+ if (userCashAccount.getBalance().subtract(studentPaymentOrder.getExpectAmount()).doubleValue() >= 0) {
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(orderNo, practiceGroupBuyParams.getOrganId(), amount);
|
|
|
+
|
|
|
+ // 更新订单信息
|
|
|
+ studentPaymentOrder.setActualAmount(new BigDecimal(0));
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(studentPaymentOrder.getExpectAmount());
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setUpdateTime(now);
|
|
|
+ studentPaymentOrder.setOrganId(practiceGroupBuyParams.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(practiceGroupBuyParams.getOrganId());
|
|
|
+
|
|
|
+ sysUserCashAccountService.updateBalance(practiceGroupBuyParams.getStudentId(), studentPaymentOrder.getExpectAmount().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "网管课购买");
|
|
|
+
|
|
|
+ studentPaymentOrder.setPayTime(now);
|
|
|
+ this.orderCallback(studentPaymentOrder);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("orderNo", studentPaymentOrder.getOrderNo());
|
|
|
+
|
|
|
+ return BaseController.succeed(result);
|
|
|
+ } else {
|
|
|
+ if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
+ balance = userCashAccount.getBalance();
|
|
|
+ sysUserCashAccountService.updateBalance(practiceGroupBuyParams.getStudentId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "网管课购买");
|
|
|
+ amount = studentPaymentOrder.getExpectAmount().subtract(userCashAccount.getBalance());
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
|
+ } else {
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
+ Map<String, BigDecimal> classFee = new HashMap<>();
|
|
|
+ classFee.put("course", amount);
|
|
|
+ classFee.put("instrument", BigDecimal.ZERO);
|
|
|
+ classFee.put("accessories", BigDecimal.ZERO);
|
|
|
+ classFee.put("other", BigDecimal.ZERO);
|
|
|
+ try {
|
|
|
+ Map<String, Object> payMap = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ balance,
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ "网管课购买",
|
|
|
+ practiceGroupBuyParams.getName(),
|
|
|
+ practiceGroupBuyParams.getOrganId(),
|
|
|
+ "practiceBuy"
|
|
|
+ );
|
|
|
+
|
|
|
+ studentPaymentOrder.setOrganId(practiceGroupBuyParams.getOrganId());
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrder.setUpdateTime(now);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+
|
|
|
+ return BaseController.succeed(payMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("网管课购买失败:", e.getCause());
|
|
|
+ throw new BizException("订单提交超时,请尝试重新提交购买");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
public void orderCallback(StudentPaymentOrder order) {
|
|
|
StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(order.getId());
|
|
@@ -3298,6 +3711,12 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
practiceGroup.setGroupStatus(GroupStatusEnum.NORMAL);
|
|
|
practiceGroupDao.update(practiceGroup);
|
|
|
|
|
|
+ if(PracticeGroupType.COME_ON_PACKAGE.equals(practiceGroup.getType())){
|
|
|
+ Student student = studentDao.get(practiceGroup.getStudentId());
|
|
|
+ student.setComeOnPackage(2);
|
|
|
+ studentDao.update(student);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
contractService.transferPracticeCoursesContract(order.getUserId(), classGroup.getTotalClassTimes(), practiceGroup.getCoursesStartDate(), practiceGroup.getCoursesExpireDate(), order.getExpectAmount());
|
|
|
} catch (Exception e) {
|
|
@@ -3364,14 +3783,17 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<PracticeCourseDto> findUserHistoryBuyPracticeGroups(Integer userId, Long groupId) {
|
|
|
+ public List<PracticeCourseDto> findUserHistoryBuyPracticeGroups(Integer userId, Long groupId, PracticeGroupType type) {
|
|
|
List<PracticeCourseDto> userPracticeGroups;
|
|
|
if (Objects.nonNull(groupId)) {
|
|
|
PracticeGroup practiceGroup = practiceGroupDao.get(groupId);
|
|
|
+ if(Objects.isNull(practiceGroup)){
|
|
|
+ throw new BizException("课程信息不存在");
|
|
|
+ }
|
|
|
Date date = DateUtil.addSeconds(practiceGroup.getCoursesExpireDate(), 1);
|
|
|
userPracticeGroups = practiceGroupDao.findUserBuyPracticeGroupsWithDate(userId, date);
|
|
|
} else {
|
|
|
- userPracticeGroups = practiceGroupDao.findUserBuyPracticeGroups(userId);
|
|
|
+ userPracticeGroups = practiceGroupDao.findUserBuyPracticeGroups(userId,type);
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(userPracticeGroups)) {
|