Browse Source

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

yonge 5 years ago
parent
commit
c725d62d20

+ 39 - 134
mec-biz/src/main/java/com/ym/mec/biz/service/impl/EduPracticeGroupServiceImpl.java

@@ -611,7 +611,7 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
 
     @Override
     public List<SimpleUserDto> findEnableAssignTeachers(Integer subjectId, Integer studentId) {
-        Teacher student = teacherDao.get(studentId);
+        SysUser student = teacherDao.getUser(studentId);
         return practiceGroupDao.findEnableAssignTeachers(student.getOrganId(), subjectId, studentId);
     }
 
@@ -880,6 +880,9 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
         if(Objects.isNull(practiceGroupBuyParams.getFirstCourseTime())||Objects.isNull(practiceGroupBuyParams.getSecondCourseTime())){
             return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请确定上课时间");
         }
+        if(DateUtil.daysBetween(practiceGroupBuyParams.getFirstCourseTime(),practiceGroupBuyParams.getSecondCourseTime())>7){
+            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "两次课程的时间需安排在七天内");
+        }
 
         SysUser sysUser = sysUserFeignService.queryUserById(practiceGroupBuyParams.getStudentId());
 
@@ -895,9 +898,11 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
 
         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);
-        Date practiceBuyActivityExpireDate= DateUtil.stringToDate(practiceBuyActivityExpireDateConfig.getParanValue(),"yyyy-MM-dd HH:mm:ss");
+
+        List<Date> courseDates=new ArrayList<>();
+        courseDates.add(practiceGroupBuyParams.getFirstCourseTime());
+        courseDates.add(practiceGroupBuyParams.getSecondCourseTime());
+        courseDates.sort(Comparator.comparing(Date::getTime));
 
         Date now=new Date();
         LocalDate courseStartDay=LocalDate.now();
@@ -910,78 +915,18 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
         courseExpiredDate = DateUtil.addSeconds(courseExpiredDate, -1);
         practiceGroupBuyParams.setCoursesExpireDate(courseExpiredDate);
 
-//        LocalDate courseStartMonday=courseStartDay.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
-        LocalDate courseExpiredSunday=currentExpiredDay.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
-//        Date courseStartMondayDate = Date.from(courseStartMonday.atStartOfDay(DateUtil.zoneId).toInstant());
-        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{
+        if (Objects.isNull(teacherFreeTime)) {
             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;
-        if(practiceBuyActivityExpireDate.after(now)){
-            oneMonthPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceActivityPrice():practiceGroupSellPrice.getTwiceActivityPrice();
-        }else{
-            oneMonthPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceOriginalPrice():practiceGroupSellPrice.getTwiceOriginalPrice();
-        }
-        BigDecimal amount= oneMonthPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
-
-        practiceGroupBuyParams.setDrillTimesJson(drillTimesObject.toJSONString());
         practiceGroupBuyParams.setOrganId(sysUser.getOrganId());
         practiceGroupBuyParams.setSingleClassMinutes(practiceCourseMinutes);
-        practiceGroupBuyParams.setGroupStatus(GroupStatusEnum.LOCK);
-        practiceGroupBuyParams.setMemo(operatorInfo+",教务代买");
-        practiceGroupBuyParams.setType(PracticeGroupType.CHARGE);
+        practiceGroupBuyParams.setGroupStatus(GroupStatusEnum.NORMAL);
+        practiceGroupBuyParams.setMemo(operatorInfo+",试听课创建");
+        practiceGroupBuyParams.setType(PracticeGroupType.TRIAL);
         practiceGroupDao.insert(practiceGroupBuyParams);
 
         //创建班级信息
@@ -990,7 +935,7 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
         classGroup.setExpectStudentNum(1);
         classGroup.setStudentNum(1);
         classGroup.setName(practiceGroupBuyParams.getName());
-        classGroup.setTotalClassTimes(practiceCourses.size());
+        classGroup.setTotalClassTimes(2);
         classGroup.setType(ClassGroupTypeEnum.PRACTICE);
         classGroup.setDelFlag(0);
         classGroup.setGroupType(GroupType.PRACTICE);
@@ -1016,8 +961,8 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
         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.setSalary(BigDecimal.ZERO);
+        classGroupTeacherSalary.setOnlineClassesSalary(BigDecimal.ZERO);
         classGroupTeacherSalary.setGroupType(GroupType.PRACTICE);
         classGroupTeacherSalary.setCreateTime(now);
         classGroupTeacherSalary.setUpdateTime(now);
@@ -1037,25 +982,33 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
         List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
         List<TeacherAttendance> teacherAttendances = new ArrayList<>();
 
-        for (CourseSchedule courseSchedule : practiceCourses) {
-            //课表
+        List<CourseSchedule> practiceCourses = new ArrayList<>();
+        for (Date courseDate : courseDates) {
+            CourseSchedule courseSchedule=new CourseSchedule();
+            LocalDateTime courseStartDateTime = LocalDateTime.ofInstant(courseDate.toInstant(), DateUtil.zoneId);
+            LocalDateTime courseEndDateTime = courseStartDateTime.plusMinutes(practiceCourseMinutes);
+            courseSchedule.setClassDate(Date.from(courseStartDay.atStartOfDay(DateUtil.zoneId).toInstant()));
+            courseSchedule.setStartClassTime(Date.from(courseStartDateTime.atZone(DateUtil.zoneId).toInstant()));
+            courseSchedule.setEndClassTime(Date.from(courseEndDateTime.atZone(DateUtil.zoneId).toInstant()));
+            courseSchedule.setName(practiceGroupBuyParams.getName());
+            courseSchedule.setTeacherId(practiceGroupBuyParams.getUserId());
+            courseSchedule.setActualTeacherId(practiceGroupBuyParams.getUserId());
+            courseSchedule.setTeachMode(TeachModeEnum.ONLINE);
+            courseSchedule.setGroupType(GroupType.PRACTICE);
+            courseSchedule.setType(CourseSchedule.CourseScheduleType.PRACTICE);
+            courseSchedule.setStatus(CourseStatusEnum.NOT_START);
             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.setIsLock(0);
+            practiceCourses.add(courseSchedule);
         }
+        practiceCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
         courseScheduleDao.batchAddCourseSchedules(practiceCourses);
-        TeacherDefaultPracticeGroupSalary teacherDefaultPracticeGroupSalary = teacherDefaultPracticeGroupSalaryDao.findByTeacherAndCourseMinutes(practiceGroupBuyParams.getUserId(),practiceCourseMinutes);
-        BigDecimal teacherDefaultSalary=new BigDecimal(practiceCourseSalaryConfig.getParanValue());
-        if(Objects.nonNull(teacherDefaultPracticeGroupSalary)){
-            teacherDefaultSalary=teacherDefaultPracticeGroupSalary.getMainTeacherSalary();
-        }
-        BigDecimal studentSingleCourseCost=amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+
+        BigDecimal teacherDefaultSalary=BigDecimal.ZERO;
         for (CourseSchedule courseSchedule : practiceCourses) {
             //课程与老师薪水表
             CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
@@ -1076,7 +1029,7 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
             courseScheduleStudentPayment.setMusicGroupId(practiceGroupBuyParams.getId().toString());
             courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
             courseScheduleStudentPayment.setUserId(practiceGroupBuyParams.getStudentId());
-            courseScheduleStudentPayment.setExpectPrice(studentSingleCourseCost);
+            courseScheduleStudentPayment.setExpectPrice(BigDecimal.ZERO);
             courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
             courseScheduleStudentPayment.setCreateTime(now);
             courseScheduleStudentPayment.setUpdateTime(now);
@@ -1100,7 +1053,7 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
             courseScheduleService.checkNewCourseSchedulesWithoutMusicGroup(practiceCourses,false);
         } catch (Exception e) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-            String errMessage=new String();
+            String errMessage;
             if(e.getMessage().indexOf("主教冲突")!=-1){
                 errMessage="抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。";
             }else{
@@ -1112,54 +1065,6 @@ public class EduPracticeGroupServiceImpl implements EduPracticeGroupService{
             }
             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.setMemo(operatorInfo+",教务代买");
-        studentPaymentOrder.setVersion(0);
-        studentPaymentOrderService.insert(studentPaymentOrder);
-
-        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){
-                // 更新订单信息
-                studentPaymentOrder.setActualAmount(new BigDecimal(0));
-                studentPaymentOrder.setBalancePaymentAmount(studentPaymentOrder.getExpectAmount());
-                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
-                studentPaymentOrder.setUpdateTime(now);
-                studentPaymentOrder.setOrganId(practiceGroupBuyParams.getOrganId());
-                studentPaymentOrder.setRoutingOrganId(42);
-
-                sysUserCashAccountService.updateBalance(practiceGroupBuyParams.getStudentId(), studentPaymentOrder.getExpectAmount().negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,operatorInfo+",教务代买");
-
-                studentPaymentOrder.setPayTime(now);
-                this.orderCallback(studentPaymentOrder);
-
-                Map<String,Object> result=new HashMap<>();
-                result.put("orderNo",studentPaymentOrder.getOrderNo());
-
-                return BaseController.succeed(result);
-            }else{
-                throw new BizException("账户余额不足,请完成账户充值");
-            }
-        }else{
-            throw new BizException("当前购买方式暂时只支持用户余额购买");
-        }
+        return BaseController.succeed();
     }
 }