소스 검색

Merge remote-tracking branch 'origin/master'

周箭河 5 년 전
부모
커밋
52b687ab93

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -97,4 +97,15 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
     List<Integer> findNotStartCourseStudentPaymentIdsWithClassGroupAndStudent(@Param("classGroupId") Integer classGroupId,
                                                                               @Param("userId") Integer userId);
 
+    /**
+     * @describe 获取小课指定形式下最后一节课的课程单价
+     * @author Joburgess
+     * @date 2019/12/5
+     * @param vipGroupId: 小课编号
+     * @param teachMode: 教学形式
+     * @return java.math.BigDecimal
+     */
+    BigDecimal findVipGroupCoursePrice(@Param("vipGroupId") Integer vipGroupId,
+                                       @Param("teachMode") String teachMode);
+
 }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/ClassGroupStudentMapper.java

@@ -36,6 +36,16 @@ public class ClassGroupStudentMapper {
 	/**  */
 	private java.util.Date createTime;
 
+	private String userName;
+
+	public String getUserName() {
+		return userName;
+	}
+
+	public void setUserName(String userName) {
+		this.userName = userName;
+	}
+
 	public String getMusicGroupId() {
 		return musicGroupId;
 	}

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysMessageConfig.java

@@ -28,6 +28,16 @@ public class SysMessageConfig {
 	
 	private String group;
 
+	private Integer sendFlag;
+
+	public Integer getSendFlag() {
+		return sendFlag;
+	}
+
+	public void setSendFlag(Integer sendFlag) {
+		this.sendFlag = sendFlag;
+	}
+
 	public void setId(Integer id) {
 		this.id = id;
 	}

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -367,7 +367,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 			latestCourseSchedule = courseSchedules.stream().max(Comparator.comparing(CourseSchedule::getEndClassTime)).get();
 		}
 		//获取第一节课和最后一节课所包含的时间段内已存在的课程
-		List<CourseSchedule> existCourseSchedules = courseScheduleDao.findAllCourseByDateZone(firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
+		List<CourseSchedule> existCourseSchedules = courseScheduleDao
+				.findAllCourseByDateZone(firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
 
 		//只需要调整课程信息的课程编号列表
 		List<Long> updateCourseScheduleIds = courseSchedules

+ 5 - 43
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
 import javax.annotation.Resource;
 
 import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.biz.service.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -59,21 +60,6 @@ import com.ym.mec.biz.dal.entity.Subject;
 import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.dal.page.StudentRegistrationQueryInfo;
-import com.ym.mec.biz.service.ClassGroupRelationService;
-import com.ym.mec.biz.service.ClassGroupService;
-import com.ym.mec.biz.service.ClassGroupStudentMapperService;
-import com.ym.mec.biz.service.ContractService;
-import com.ym.mec.biz.service.CourseScheduleService;
-import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
-import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
-import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
-import com.ym.mec.biz.service.SubjectService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.SysMessageService;
-import com.ym.mec.biz.service.SysUserCashAccountDetailService;
-import com.ym.mec.biz.service.SysUserCashAccountService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.entity.ImGroupMember;
 import com.ym.mec.common.entity.ImGroupModel;
@@ -129,6 +115,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
     @Autowired
+    private MusicGroupPaymentCalenderService musicGroupPaymentCalenderService;
+    @Autowired
     private SubjectService subjectService;
     @Autowired
     private SysConfigDao sysConfigDao;
@@ -592,19 +580,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 //添加班级关联
                 addStudents(classGroup, userId);
                 Date date = new Date();
-                //获取当前月
-                Integer month = Integer.parseInt(DateUtil.getMonth(date));
-                //获取下次缴费月份
-                List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
-                List<Integer> months = musicGroupPaymentCalenders.stream().map(e -> e.getPaymentMonth()).collect(Collectors.toList());
-                for (int i = 0; i < months.size(); i++) {
-                    if (months.get(i).equals(month)) {
-                        month = i == months.size() - 1 ? months.get(0) : months.get(i + 1);
-                    }
-                }
-                Calendar calendar = Calendar.getInstance();
-                calendar.add(Calendar.MONTH, month);
-                DateUtil.getFirstDayOfMonth(calendar.getTime());
                 //保存乐团学生费用表
                 if (studentAddDto.getCourseFee() == null) {
                     MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, studentRegistration.getActualSubjectId());
@@ -612,7 +587,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 }
                 musicGroupStudentFeeDao.insert(new MusicGroupStudentFee(musicGroupId,
                         userId, studentRegistration.getSubjectId(), studentAddDto.getCourseFee(),
-                        DateUtil.getFirstDayOfMonth(calendar.getTime()), studentAddDto.getTemporaryCourseFee()));
+                        musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId), studentAddDto.getTemporaryCourseFee()));
                 //生成订单
                 StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
                 studentPaymentOrder.setUserId(userId);
@@ -798,19 +773,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 //添加学生
                 //classGroupStudentMapperService.addStudents(waitPayOrder.getClassGroupId(), studentRegistration.getUserId().toString(), GroupType.MUSIC);
             } else {
-                //获取当前月
-                Integer month = Integer.parseInt(DateUtil.getMonth(nowDate));
-                //获取下次缴费月份
-                List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByMusicGroupId(studentRegistration.getMusicGroupId());
-                List<Integer> months = musicGroupPaymentCalenders.stream().map(e -> e.getPaymentMonth()).collect(Collectors.toList());
-                for (int i = 0; i < months.size(); i++) {
-                    if (months.get(i).equals(month)) {
-                        month = i == months.size() - 1 ? months.get(0) : months.get(i + 1);
-                    }
-                }
-                Calendar calendar = Calendar.getInstance();
-                calendar.add(Calendar.MONTH, month);
-
                 //加入缴费周期
                 MusicGroupStudentFee musicGroupStudentFee = new MusicGroupStudentFee();
                 musicGroupStudentFee.setMusicGroupId(studentRegistration.getMusicGroupId());
@@ -818,7 +780,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 musicGroupStudentFee.setCourseFee(musicOneSubjectClassPlan.getFee());
                 musicGroupStudentFee.setCreateTime(nowDate);
                 musicGroupStudentFee.setUpdateTime(nowDate);
-                musicGroupStudentFee.setNextPaymentDate(DateUtil.getFirstDayOfMonth(calendar.getTime()));
+                musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(studentRegistration.getMusicGroupId()));
                 musicGroupStudentFee.setLatestPaidTime(nowDate);
                 musicGroupStudentFee.setSubjectId(studentRegistration.getActualSubjectId());
                 musicGroupStudentFee.setPaymentStatus(MusicGroupStudentFee.PaymentStatus.PAID_COMPLETED);

+ 4 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMessageServiceImpl.java

@@ -67,7 +67,6 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 
 	/**
 	 * 添加消息
-	 * @param userId 用户编号
 	 * @param subject 消息主题
 	 * @param content 消息内容
 	 * @param receivers 接收人,多个人用逗号分开
@@ -136,6 +135,8 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 		SysMessageConfig messageConfig = sysMessageConfigService.queryByType(messageType);
 		if (messageConfig == null) {
 			throw new BizException("消息类型错误");
+		}else if(messageConfig.getSendFlag() == null || messageConfig.getSendFlag() == 0){
+			return true;
 		}
 		Date date = new Date();
 		SendStatusEnum status = SendStatusEnum.SUCCESSED;
@@ -219,6 +220,8 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 		SysMessageConfig messageConfig = sysMessageConfigService.queryByType(type);
 		if (messageConfig == null) {
 			throw new BizException("消息类型错误");
+		}else if(messageConfig.getSendFlag() == null || messageConfig.getSendFlag() == 0){
+			return;
 		}
 		Date date = new Date();
 		SendStatusEnum status = SendStatusEnum.WAIT;

+ 53 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1549,22 +1549,45 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			throw new BizException("指定的vip课不存在");
 		}
 		ClassGroup classGroup = classGroupDao.findByVipGroup(vipGroup.getId(), null);
+		if(Objects.isNull(classGroup)){
+			throw new BizException("班级不存在");
+		}
+
+		Date now=new Date();
+
+		BigDecimal onlineCoursePrice = courseScheduleStudentPaymentDao.findVipGroupCoursePrice(vipGroup.getId().intValue(),TeachModeEnum.ONLINE.getCode());
+		if(Objects.isNull(onlineCoursePrice)){
+			onlineCoursePrice = new BigDecimal(0);
+		}
+		BigDecimal offlineCoursePrice = courseScheduleStudentPaymentDao.findVipGroupCoursePrice(vipGroup.getId().intValue(),TeachModeEnum.OFFLINE.getCode());
+		if(Objects.isNull(offlineCoursePrice)){
+			offlineCoursePrice = new BigDecimal(0);
+		}
+
+		BigDecimal surplusCourseTotalPrice = new BigDecimal(0);
+
 		//课程信息调整
-		vipGroupApplyDto.getCourseSchedules().forEach(courseSchedule -> {
+		for (CourseSchedule courseSchedule : vipGroupApplyDto.getCourseSchedules()) {
 			courseSchedule.setSchoolId(vipGroup.getTeacherSchoolId());
 			courseSchedule.setTeacherId(vipGroup.getUserId());
 			courseSchedule.setActualTeacherId(vipGroup.getUserId());
 			courseSchedule.setStatus(CourseStatusEnum.NOT_START);
 			courseSchedule.setType(CourseSchedule.CourseScheduleType.VIP);
 			courseSchedule.setClassGroupId(classGroup.getId());
-			courseSchedule.setGroupType(GroupType.MUSIC);
+			courseSchedule.setGroupType(GroupType.VIP);
 			courseSchedule.setMusicGroupId(vipGroup.getId().toString());
-		});
+			if (courseSchedule.getTeachMode().equals(TeachModeEnum.ONLINE)) {
+				surplusCourseTotalPrice = surplusCourseTotalPrice.add(onlineCoursePrice);
+			} else if (courseSchedule.getTeachMode().equals(TeachModeEnum.OFFLINE)) {
+				surplusCourseTotalPrice = surplusCourseTotalPrice.add(offlineCoursePrice);
+			}
+		}
+
 		courseScheduleService.batchAddCourseSchedule(vipGroupApplyDto.getCourseSchedules());
 
 		TeacherDefaultVipGroupSalary byTeacherAndCategory = teacherDefaultVipGroupSalaryDao.findByTeacherAndCategory(vipGroup.getUserId(), vipGroup.getVipGroupCategoryId());
 
-		BigDecimal onlineTeacherSalary=new BigDecimal(0),offlineTeacherSalary=new BigDecimal(0);
+		BigDecimal onlineTeacherSalary,offlineTeacherSalary;
 		if(Objects.nonNull(byTeacherAndCategory)){
 			onlineTeacherSalary=byTeacherAndCategory.getOnlineClassesSalary();
 			offlineTeacherSalary=byTeacherAndCategory.getOfflineClassesSalary();
@@ -1586,7 +1609,29 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		List<ImGroupMember> imGroupMemberList = new ArrayList<>();
 		//生成学生单课缴费信息
 		for (ClassGroupStudentMapper classGroupStudent : classGroupStudents) {
-			courseScheduleStudentPaymentService.createCourseScheduleStudentPaymentForVipGroup(vipGroup.getId(),classGroupStudent.getUserId());
+			SysUserCashAccount sysUserCashAccount = sysUserCashAccountService.get(classGroupStudent.getUserId());
+			if(sysUserCashAccount.getCourseBalance().compareTo(surplusCourseTotalPrice)<0){
+				throw new BizException("[{}]学生课程余额不足",classGroupStudent.getUserName());
+			}
+			List<CourseScheduleStudentPayment> courseScheduleStudentPayments=new ArrayList<>();
+			for (CourseSchedule vipGroupCourseSchedule : vipGroupApplyDto.getCourseSchedules()) {
+				CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
+				courseScheduleStudentPayment.setGroupType(GroupType.VIP);
+				courseScheduleStudentPayment.setMusicGroupId(vipGroup.getId().toString());
+				courseScheduleStudentPayment.setClassGroupId(vipGroupCourseSchedule.getClassGroupId());
+				courseScheduleStudentPayment.setCourseScheduleId(vipGroupCourseSchedule.getId());
+				courseScheduleStudentPayment.setUserId(classGroupStudent.getUserId());
+				if(vipGroupCourseSchedule.getTeachMode().equals(TeachModeEnum.ONLINE)){
+					courseScheduleStudentPayment.setExpectPrice(onlineCoursePrice);
+				}else if(vipGroupCourseSchedule.getTeachMode().equals(TeachModeEnum.OFFLINE)){
+					courseScheduleStudentPayment.setExpectPrice(offlineCoursePrice);
+				}
+				courseScheduleStudentPayment.setCreateTime(now);
+				courseScheduleStudentPayment.setUpdateTime(now);
+				courseScheduleStudentPayments.add(courseScheduleStudentPayment);
+			}
+			sysUserCashAccountService.updateCourseBalance(classGroupStudent.getUserId(),sysUserCashAccount.getCourseBalance().subtract(surplusCourseTotalPrice));
+			courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
 			imGroupMemberList.add(new ImGroupMember(classGroupStudent.getUserId().toString()));
 		}
 		ImGroupMember[] imGroupMembers = imGroupMemberList.toArray(new ImGroupMember[imGroupMemberList.size()]);
@@ -1742,6 +1787,9 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
             List<VipGroup> needUpdateVipGroups = new ArrayList<>();
             for (VipGroup vipGroup : normalVipGroupList) {
                 try {
+                	if(Objects.isNull(vipGroup.getRegistrationStartTime())){
+                		continue;
+					}
                     if(now.before(vipGroup.getRegistrationStartTime())){
                         vipGroup.setStatus(VipGroupStatusEnum.NOT_START);
                     }

+ 8 - 2
mec-biz/src/main/resources/config/mybatis/ClassGroupStudentMapperMapper.xml

@@ -13,6 +13,7 @@
         <result column="class_group_id_" property="classGroupId"/>
         <result column="user_id_" property="userId"/>
         <result column="create_time_" property="createTime"/>
+        <result column="username_" property="userName"/>
         <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
     </resultMap>
 
@@ -175,8 +176,13 @@
         AND status_ = 'NORMAL'
     </select>
     <select id="findByClassGroup" resultMap="ClassGroupStudentMapper">
-        SELECT * FROM class_group_student_mapper WHERE class_group_id_ = #{classGroupId}
-        AND status_ = 'NORMAL'
+        SELECT
+          cgsm.*,
+	      su.username_
+        FROM class_group_student_mapper cgsm
+            LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
+        WHERE class_group_id_ = #{classGroupId}
+          AND status_ = 'NORMAL'
     </select>
 
     <!-- 查询班级某状态的所有学生 -->

+ 15 - 1
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -166,7 +166,21 @@
 		SELECT id_ FROM course_schedule_student_payment WHERE class_group_id_=#{classGroupId} AND user_id_=#{userId}
 	</select>
 
-	<delete id="deleteStudentCourseSchedule">
+    <select id="findVipGroupCoursePrice" resultType="java.math.BigDecimal">
+		SELECT
+			cssp.expect_price_
+		FROM
+			course_schedule cs
+			LEFT JOIN course_schedule_student_payment cssp ON cs.id_ = cssp.course_schedule_id_
+		WHERE
+			cs.music_group_id_ = #{vipGroupId}
+			AND cs.teach_mode_ = #{teachMode}
+			AND cs.group_type_ = 'VIP'
+			AND cssp.expect_price_ IS NOT NULL
+		ORDER BY CONCAT(cs.class_date_,' ',cs.start_class_time_) DESC LIMIT 1
+	</select>
+
+    <delete id="deleteStudentCourseSchedule">
 		DELETE FROM course_schedule_student_payment WHERE user_id_ = #{userId} AND course_schedule_id_ IN
 		<foreach collection="courseScheduleList" item="courseSchedule" index="index" open="(" close=")" separator=",">
 			#{courseSchedule.id}

+ 7 - 0
mec-biz/src/main/resources/config/mybatis/SysMessageConfigMapper.xml

@@ -13,6 +13,7 @@
 		<result column="modify_on_" property="modifyOn" />
 		<result column="url_" property="url" />
 		<result column="group_" property="group" />
+		<result column="send_flag_" property="sendFlag" />
 	</resultMap>
 
 	<sql id="queryCondition">
@@ -30,6 +31,9 @@
 			<if test="group != null">
 				and group_ = #{group,jdbcType=VARCHAR}
 			</if>
+			<if test="sendFlag != null">
+				and send_flag_ = #{sendFlag}
+			</if>
 		</where>
 	</sql>
 
@@ -80,6 +84,9 @@
 			<if test="description != null">
 				description_ = #{description},
 			</if>
+			<if test="sendFlag != null">
+				send_flag_ = #{sendFlag}
+			</if>
 		</set>
 		WHERE id_ = #{id}
 	</update>

+ 4 - 3
mec-biz/src/main/resources/config/mybatis/VipGroupMapper.xml

@@ -299,10 +299,10 @@
 
     <sql id="studentVipGroupQueryCondition">
         <where>
-            vg.status_!=3
-            AND vg.audit_status_='PASS'
+            vg.audit_status_='PASS'
             AND vg.status_=1
             AND vg.courses_expire_date_ &gt;= DATE_FORMAT(NOW(),'%Y%m%d')
+            AND vg.courses_start_date &gt; NOW()
             AND (select count(1) as num from student_payment_order where vg.id_ = music_group_id_ AND user_id_=#{userId} AND status_='SUCCESS') = 0
             <if test="subjectId!=null">
                AND FIND_IN_SET(#{subjectId},cg.subject_id_list_)
@@ -740,7 +740,8 @@
         FROM
           vip_group
         WHERE
-          payment_expire_date_ &lt; DATE_FORMAT(NOW( ),'%Y-%m-%d')
+          (payment_expire_date_ &lt; DATE_FORMAT(NOW( ),'%Y-%m-%d')
+          OR courses_start_date &lt; NOW())
           AND status_ =1
     </select>