Sfoglia il codice sorgente

feat:六一活动排课

Joburgess 4 anni fa
parent
commit
6e37e906a7

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/VipGroupService.java

@@ -41,6 +41,15 @@ public interface VipGroupService extends BaseService<Long, VipGroup> {
     HttpResponseResult createVipGroup(VipGroupApplyDto vipGroup);
 
     /**
+     * @describe 创建vip课
+     * @author Joburgess
+     * @date 2019/10/30
+     * @param vipGroup: VIP课申请信息
+     * @return void
+     */
+    HttpResponseResult createActivityVipGroup(VipGroupApplyDto vipGroup);
+
+    /**
      * @describe 获取教务与教师共有分部
      * @author Joburgess
      * @date 2020.07.08

+ 303 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -471,6 +471,309 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+	public HttpResponseResult createActivityVipGroup(VipGroupApplyDto vipGroup) {
+		if (Objects.isNull(vipGroup.getVipGroupApplyBaseInfo().getUserId())){
+			throw new BizException("请选择指导老师");
+		}
+
+		if(vipGroup.getCourseSchedules().size()!=(vipGroup.getVipGroupApplyBaseInfo().getOfflineClassesNum()+vipGroup.getVipGroupApplyBaseInfo().getOnlineClassesNum())){
+			throw new BizException("建课失败,当前课程存在未排课课程,请调整相关设置");
+		}
+
+		Map<TeachModeEnum, List<CourseSchedule>> courseScheduleGroup;
+		try {
+			courseScheduleGroup = vipGroup.getCourseSchedules().stream().collect(Collectors.groupingBy(CourseSchedule::getTeachMode));
+		} catch (Exception e) {
+			throw new BizException("教学模式错误");
+		}
+
+		if((Objects.isNull(courseScheduleGroup.get(TeachModeEnum.OFFLINE))&&vipGroup.getVipGroupApplyBaseInfo().getOfflineClassesNum()!=0)
+				||(!Objects.isNull(courseScheduleGroup.get(TeachModeEnum.OFFLINE))&&(courseScheduleGroup.get(TeachModeEnum.OFFLINE).size()<vipGroup.getVipGroupApplyBaseInfo().getOfflineClassesNum()))){
+			throw new BizException("线下课课时数量安排有误");
+		}
+
+		if((Objects.isNull(courseScheduleGroup.get(TeachModeEnum.ONLINE))&&vipGroup.getVipGroupApplyBaseInfo().getOnlineClassesNum()!=0)
+				||(!Objects.isNull(courseScheduleGroup.get(TeachModeEnum.ONLINE))&&(courseScheduleGroup.get(TeachModeEnum.ONLINE).size()<vipGroup.getVipGroupApplyBaseInfo().getOnlineClassesNum()))){
+			throw new BizException("线上课课时数量安排有误");
+		}
+
+		if(vipGroup.getVipGroupApplyBaseInfo().getOfflineClassesNum()>0
+				&&Objects.isNull(vipGroup.getVipGroupApplyBaseInfo().getTeacherSchoolId())){
+			throw new BizException("请设置教学点");
+		}
+
+		String studentIds=vipGroup.getStudentIds();
+		List<String> studentIdList=new ArrayList<>();
+		if(StringUtils.isNotBlank(studentIds)){
+			studentIdList = Arrays.asList(studentIds.split(","));
+		}
+
+		Date now=new Date();
+
+		VipGroupApplyBaseInfoDto vipGroupApplyBaseInfoDto=vipGroup.getVipGroupApplyBaseInfo();
+
+		if(Objects.isNull(vipGroupApplyBaseInfoDto.getOfflineClassesUnitPrice())
+				&&Objects.isNull(vipGroupApplyBaseInfoDto.getOnlineClassesUnitPrice())){
+			throw new BizException("请设置课程单价");
+		}
+
+		if(StringUtils.isBlank(vipGroupApplyBaseInfoDto.getStudentIdList())){
+			throw new BizException("请选择学员");
+		}
+
+		if(Objects.isNull(vipGroupApplyBaseInfoDto.getOnlineTeacherSalary())||Objects.isNull(vipGroupApplyBaseInfoDto.getOfflineTeacherSalary())){
+			throw new BizException("请设置教师课酬");
+		}
+
+		Integer totalClassTimes=vipGroupApplyBaseInfoDto.getOnlineClassesNum()+vipGroupApplyBaseInfoDto.getOfflineClassesNum();
+		//获取第一节课
+		CourseSchedule firstCourseSchedule = vipGroup.getCourseSchedules().stream().min(Comparator.comparing(CourseSchedule::getStartClassTime)).get();
+		//获取最后一节课
+		CourseSchedule latestCourseSchedule = vipGroup.getCourseSchedules().stream().max(Comparator.comparing(CourseSchedule::getEndClassTime)).get();
+
+		if(firstCourseSchedule.getStartClassTime().before(now)){
+			throw new BizException("开课时间不能小于当前时间");
+		}
+
+		if(vipGroupApplyBaseInfoDto.getRegistrationStartTime().after(vipGroupApplyBaseInfoDto.getPaymentExpireDate())){
+			throw new BizException("报名开始时间必须在报名截至时间之前");
+		}
+
+		if(vipGroupApplyBaseInfoDto.getPaymentExpireDate().after(firstCourseSchedule.getStartClassTime())
+				||DateUtil.isSameDay(vipGroupApplyBaseInfoDto.getPaymentExpireDate(),firstCourseSchedule.getEndClassTime())){
+			throw new BizException("创建失败,报名截止时间必须在开课时间前一天");
+		}
+
+		List<Integer> canBuyStudentIds = Arrays.stream(vipGroupApplyBaseInfoDto.getStudentIdList().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList());
+		List<VipGroupStudentCoursePrice> vscps = vipGroup.getVipGroupApplyBaseInfo().getVipGroupStudentCoursePrices();
+
+		//获取活动信息
+		VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupApplyBaseInfo().getVipGroupActivityId());
+		if(!vipGroup.getAllowOverstepActivityStudentNum()&&Objects.nonNull(vipGroupActivity)&&Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes())&&vipGroupActivity.getStudentMaxUsedTimes()!=-1&&StringUtils.isNotBlank(vipGroupApplyBaseInfoDto.getStudentIdList())){
+			List<String> tempStudentIds = Arrays.asList(vipGroupApplyBaseInfoDto.getStudentIdList().split(","));
+			List<Integer> errStudentIds = new ArrayList<>();
+			for (String studentIdStr : tempStudentIds) {
+				int useNum = vipGroupDao.countStudentUserActivityNum(vipGroup.getVipGroupApplyBaseInfo().getVipGroupActivityId(), Integer.valueOf(studentIdStr));
+				if(useNum>=vipGroupActivity.getStudentMaxUsedTimes()){
+					errStudentIds.add(Integer.valueOf(studentIdStr));
+				}
+			}
+			if(errStudentIds.size()>0){
+				List<SimpleUserDto> students = teacherDao.getUsersSimpleInfo(errStudentIds);
+				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+				String studentNames = StringUtils.join(students.stream().map(SimpleUserDto::getNickName).collect(Collectors.toList()), "、");
+				return BaseController.failed(HttpStatus.PARTIAL_CONTENT,"该活动"+studentNames+"学员创建及成课之和已达上限,是否继续创建该课程?");
+			}
+		}
+		//判断课程安排是否超出范围
+		if(Objects.nonNull(vipGroupActivity)&&(Objects.nonNull(vipGroupActivity.getCoursesEndTime())||Objects.nonNull(vipGroupActivity.getCoursesStartTime()))){
+			if(latestCourseSchedule.getEndClassTime().after(vipGroupActivity.getCoursesEndTime())
+					||firstCourseSchedule.getStartClassTime().before(vipGroupActivity.getCoursesStartTime())){
+				throw new BizException("课时安排时间超出范围!");
+			}
+		}else{
+			VipGroupDefaultClassesCycle vipGroupDefaultClassesCycle = vipGroupDefaultClassesCycleDao.findByOrganAndClassTimes(totalClassTimes);
+
+			if (vipGroupDefaultClassesCycle != null) {
+				int month = DateUtil.monthsBetween(firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
+				if (month > vipGroupDefaultClassesCycle.getMonth()) {
+					throw new BizException("课时安排时间超出范围!");
+				}
+			}
+		}
+
+		if(Objects.nonNull(vipGroupActivity)&&Objects.nonNull(vipGroupActivity.getMinCourseNum())&&vipGroupActivity.getMinCourseNum()!=-1&&Objects.nonNull(vipGroupActivity.getMaxCourseNum())&&vipGroupActivity.getMaxCourseNum()!=-1){
+			Integer requestCourseNum = vipGroupApplyBaseInfoDto.getOnlineClassesNum() + vipGroupApplyBaseInfoDto.getOfflineClassesNum();
+			if(requestCourseNum.compareTo(vipGroupActivity.getMinCourseNum())<0||requestCourseNum.compareTo(vipGroupActivity.getMaxCourseNum())>0){
+				throw new BizException("该活动课时数为{}节~{}节", vipGroupActivity.getMinCourseNum(), vipGroupActivity.getMaxCourseNum());
+			}
+		}
+
+		int repeatVipGroups = vipGroupDao.countUserRepeatVipGroupInCourseStartEndTime(vipGroupApplyBaseInfoDto.getUserId(), firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
+		if(repeatVipGroups>0){
+			throw new BizException("请勿重复提交");
+		}
+
+		VipGroupCategory vipGroupCategory = vipGroupCategoryDao.get(vipGroupApplyBaseInfoDto.getVipGroupCategoryId());
+		if(Objects.isNull(vipGroupCategory)){
+			throw new BizException("课程形式不存在");
+		}
+		List<String> studentNames = studentDao.getStudentNames(canBuyStudentIds);
+
+		//生成vip课信息
+		List<String> bySubIds = subjectDao.findBySubIds(vipGroupApplyBaseInfoDto.getSubjectIdList());
+		StringBuffer className=new StringBuffer();
+		if(Objects.isNull(vipGroupCategory.getMusicTheory())||!vipGroupCategory.getMusicTheory()){
+			className.append(StringUtils.join(bySubIds,","));
+			className.append(vipGroupCategory.getName());
+		}else{
+			className.append("乐理课•");
+		}
+		className.append(StringUtils.join(studentNames, ","));
+		vipGroupApplyBaseInfoDto.setName(className.toString());
+
+		//计算课程相关费用信息
+		Map<String, BigDecimal> costInfo = countVipGroupPredictFee(vipGroupApplyBaseInfoDto,
+				vipGroupApplyBaseInfoDto.getUserId(), null);
+
+		vipGroupApplyBaseInfoDto.setAuditStatus(AuditStatusEnum.PASS);
+
+		//如果默认课酬与实际课酬不匹配则需要审批
+		if(costInfo.get("offlineTeacherSalary").compareTo(vipGroupApplyBaseInfoDto.getOfflineTeacherSalary())<0||
+				costInfo.get("onlineTeacherSalary").compareTo(vipGroupApplyBaseInfoDto.getOnlineTeacherSalary())<0
+						&&StringUtils.isBlank(studentIds)){
+			vipGroupApplyBaseInfoDto.setAuditStatus(AuditStatusEnum.ING);
+		}
+
+		vipGroupApplyBaseInfoDto.setTotalPrice(costInfo.get("totalPrice"));
+		if(StringUtils.isNotBlank(studentIds)){
+			vipGroupApplyBaseInfoDto.setStatus(VipGroupStatusEnum.PROGRESS);
+		}else{
+			vipGroupApplyBaseInfoDto.setStatus(VipGroupStatusEnum.APPLYING);
+		}
+		if(CollectionUtils.isEmpty(vscps)){
+			vscps = new ArrayList<>();
+			for (Integer canBuyStudentId : canBuyStudentIds) {
+				vscps.add(new VipGroupStudentCoursePrice(canBuyStudentId, vipGroupApplyBaseInfoDto.getOfflineClassesUnitPrice(), vipGroupApplyBaseInfoDto.getOfflineClassesUnitPrice(), vipGroupApplyBaseInfoDto.getTotalPrice()));
+			}
+		}
+		Teacher teacher = teacherService.get(vipGroupApplyBaseInfoDto.getUserId());
+		if(Objects.isNull(teacher)){
+			throw new BizException("教师不存在");
+		}
+		if(Objects.isNull(teacher.getTeacherOrganId())){
+			throw new BizException("教师部门异常");
+		}
+//        vipGroupApplyBaseInfoDto.setOrganId(Integer.parseInt(teacher.getOrganId()));
+		//开课时间为排课的第一节课的开始时间
+		vipGroupApplyBaseInfoDto.setCourseStartDate(firstCourseSchedule.getStartClassTime());
+		//课程结束时间为排课的最后一节课的结束时间
+		vipGroupApplyBaseInfoDto.setCoursesExpireDate(latestCourseSchedule.getEndClassTime());
+
+		vipGroupApplyBaseInfoDto.setPaymentExpireDate(DateUtil.getLastSecondWithDay(vipGroupApplyBaseInfoDto.getPaymentExpireDate()));
+
+		VipGroupDefaultClassesUnitPrice vipGroupDefaultClassesUnitPrice = vipGroupDefaultClassesUnitPriceDao.getByVipGroupCategory(vipGroup.getVipGroupApplyBaseInfo().getVipGroupCategoryId(), vipGroup.getVipGroupApplyBaseInfo().getOrganId());
+
+		if(Objects.isNull(vipGroupDefaultClassesUnitPrice)){
+			vipGroupApplyBaseInfoDto.setAuditStatus(AuditStatusEnum.ING);
+		}else{
+			if(Objects.nonNull(vipGroupApplyBaseInfoDto.getOfflineClassesUnitPrice())
+					&&vipGroupApplyBaseInfoDto.getOfflineClassesUnitPrice().compareTo(vipGroupDefaultClassesUnitPrice.getOfflineClassesUnitPrice())!=0){
+				vipGroupApplyBaseInfoDto.setAuditStatus(AuditStatusEnum.ING);
+			}
+			if(Objects.nonNull(vipGroupApplyBaseInfoDto.getOnlineClassesUnitPrice())
+					&&vipGroupApplyBaseInfoDto.getOnlineClassesUnitPrice().compareTo(vipGroupDefaultClassesUnitPrice.getOnlineClassesUnitPrice())!=0){
+				vipGroupApplyBaseInfoDto.setAuditStatus(AuditStatusEnum.ING);
+			}
+		}
+
+		if(StringUtils.isBlank(vipGroupApplyBaseInfoDto.getStudentIdList())){
+			vipGroupApplyBaseInfoDto.setStudentIdList(StringUtils.join(vscps.stream().map(VipGroupStudentCoursePrice::getStudentId).collect(Collectors.toList()), ","));
+		}
+
+		if(vipGroup.getOnlyProgress()){
+			vipGroupApplyBaseInfoDto.setAuditStatus(AuditStatusEnum.PASS);
+		}
+
+		vipGroupDao.insert(vipGroupApplyBaseInfoDto);
+
+		vscps.forEach(e->e.setVipGroupId(vipGroupApplyBaseInfoDto.getId()));
+		vipGroupStudentCoursePriceDao.batchInsert(vscps);
+
+		vipGroup.getVipGroupApplyBaseInfo().setId(vipGroupApplyBaseInfoDto.getId());
+
+		//创建班级信息
+		ClassGroup classGroup=new ClassGroup();
+		classGroup.setSubjectIdList(vipGroupApplyBaseInfoDto.getSubjectIdList());
+		classGroup.setExpectStudentNum(vipGroupCategory.getStudentNum());
+		if(StringUtils.isNotBlank(studentIds)){
+			classGroup.setStudentNum(studentIdList.size());
+		}
+		classGroup.setName(vipGroupApplyBaseInfoDto.getName());
+		classGroup.setExpectStudentNum(vipGroupApplyBaseInfoDto.getStudentNum());
+		classGroup.setTotalClassTimes(totalClassTimes);
+		classGroup.setType(ClassGroupTypeEnum.VIP);
+		classGroup.setDelFlag(0);
+		classGroup.setGroupType(GroupType.VIP);
+		classGroup.setMusicGroupId(vipGroupApplyBaseInfoDto.getId().toString());
+		classGroup.setCreateTime(now);
+		classGroup.setUpdateTime(now);
+		classGroupDao.insert(classGroup);
+
+		//创建班级老师关联记录
+		ClassGroupTeacherMapper classGroupTeacherMapper=new ClassGroupTeacherMapper();
+		classGroupTeacherMapper.setMusicGroupId(vipGroupApplyBaseInfoDto.getId().toString());
+		classGroupTeacherMapper.setClassGroupId(classGroup.getId());
+		classGroupTeacherMapper.setTeacherRole(TeachTypeEnum.BISHOP);
+		classGroupTeacherMapper.setUserId(vipGroupApplyBaseInfoDto.getUserId());
+		classGroupTeacherMapper.setGroupType(GroupType.VIP);
+		classGroupTeacherMapper.setCreateTime(now);
+		classGroupTeacherMapper.setUpdateTime(now);
+		classGroupTeacherMapperDao.insert(classGroupTeacherMapper);
+
+		//创建班级与老师课酬记录
+		ClassGroupTeacherSalary classGroupTeacherSalary=new ClassGroupTeacherSalary();
+		classGroupTeacherSalary.setMusicGroupId(vipGroupApplyBaseInfoDto.getId().toString());
+		classGroupTeacherSalary.setClassGroupId(classGroup.getId());
+		classGroupTeacherSalary.setTeacherRole(TeachTypeEnum.BISHOP);
+		classGroupTeacherSalary.setUserId(vipGroupApplyBaseInfoDto.getUserId());
+		classGroupTeacherSalary.setSalary(vipGroupApplyBaseInfoDto.getOfflineTeacherSalary());
+		classGroupTeacherSalary.setOnlineClassesSalary(vipGroupApplyBaseInfoDto.getOnlineTeacherSalary());
+		classGroupTeacherSalary.setGroupType(GroupType.VIP);
+		classGroupTeacherSalary.setCreateTime(now);
+		classGroupTeacherSalary.setUpdateTime(now);
+		classGroupTeacherSalaryDao.insert(classGroupTeacherSalary);
+
+		//课程信息调整
+		vipGroup.getCourseSchedules().forEach(courseSchedule -> {
+			courseSchedule.setGroupType(GroupType.VIP);
+			courseSchedule.setMusicGroupId(vipGroupApplyBaseInfoDto.getId().toString());
+			if(courseSchedule.getTeachMode().equals(TeachModeEnum.OFFLINE)){
+				courseSchedule.setSchoolId(vipGroup.getVipGroupApplyBaseInfo().getTeacherSchoolId());
+			}
+			courseSchedule.setTeacherId(vipGroupApplyBaseInfoDto.getUserId());
+			courseSchedule.setActualTeacherId(vipGroupApplyBaseInfoDto.getUserId());
+			courseSchedule.setStatus(CourseStatusEnum.NOT_START);
+			courseSchedule.setType(CourseSchedule.CourseScheduleType.VIP);
+			courseSchedule.setClassGroupId(classGroup.getId());
+			courseSchedule.setName(vipGroupApplyBaseInfoDto.getName());
+			courseSchedule.setOrganId(vipGroupApplyBaseInfoDto.getOrganId());
+		});
+		courseScheduleService.checkNewCourseSchedules(vipGroup.getCourseSchedules(),false,false);
+		vipGroupApplyBaseInfoDto.setCourseSchedulesJson(JSON.toJSONString(vipGroup.getCourseSchedules()));
+		vipGroupDao.update(vipGroupApplyBaseInfoDto);
+
+		if(StringUtils.isNotBlank(studentIds)){
+			List<Integer> collect = studentIdList.stream().mapToInt(Integer::parseInt).boxed().collect(Collectors.toList());
+			classGroupService.addStudentIntoClassGroup(vipGroupApplyBaseInfoDto.getId().toString(),classGroup.getId(),collect);
+			createVipGroupCourseScheInfo(vipGroupApplyBaseInfoDto.getId(),classGroup);
+		}
+
+		Set<Integer> roleIds = new HashSet<>(1);
+		roleIds.add(SysUserRole.SECTION_MANAGER);
+		Map<String,Long> memo = new HashMap<>(1);
+		memo.put("vipGroupId",vipGroupApplyBaseInfoDto.getId());
+//		SysUser sysUser = sysUserFeignService.queryUserById(vipGroup.getVipGroupApplyBaseInfo().getUserId());
+		if(Objects.isNull(teacher)){
+			throw new BizException("该用户不存在");
+		}
+		Set<Integer> userIds = musicGroupDao.queryUserIdByRoleId(roleIds,teacher.getTeacherOrganId());
+		if(CollectionUtils.isEmpty(userIds)){
+			throw new BizException("当前分部没有运营主管,无法创建,请联系总部工作人员!");
+		}
+		if(vipGroupApplyBaseInfoDto.getEducationalTeacherId() != null){
+			userIds.add(vipGroupApplyBaseInfoDto.getEducationalTeacherId());
+		}
+//		if (vipGroup.getVipGroupApplyBaseInfo().getUserId() != null){
+//			sysMessageService.batchSeoMessage(userIds,MessageTypeEnum.BACKSTAGE_VIP_COURSE_APPLY, JSONObject.toJSONString(memo),sysUser.getUsername(),sysUser.getUsername());
+//		}else {
+		sysMessageService.batchSeoMessage(userIds,MessageTypeEnum.BACKSTAGE_TEACHER_APPLY_VIP, JSONObject.toJSONString(memo),teacher.getRealName());
+//		}
+		return BaseController.succeed(vipGroupApplyBaseInfoDto.getAuditStatus().getCode());
+	}
+
+	@Override
 	public List<Organization> getPublicOrgans(Integer eduTeacherId, Integer teacherId) {
 		if(Objects.isNull(eduTeacherId)){
 			throw new BizException("教务老师不存在");