Joburgess 4 년 전
부모
커밋
33826738bf

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDao.java

@@ -362,4 +362,6 @@ public interface StudentPaymentOrderDao extends BaseDAO<Long, StudentPaymentOrde
      */
     List<StudentVipDouble11Dto> queryDouble11Students(Map<String, Object> params);
     int countDouble11Students(Map<String, Object> params);
+
+    List<StudentVipDouble11Dto> findStudentsDouble11Infos(@Param("studentIds") List<Integer> studentIds);
 }

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

@@ -42,6 +42,15 @@ public interface StudentManageService {
     PageInfo<StudentVipDouble11Dto> queryDouble11Students(StudentManageQueryInfo queryInfo);
 
     /**
+     * @describe 获取学员双11记录
+     * @author qnc99
+     * @date 2020/11/26 0026
+     * @param studentIds:
+     * @return java.util.List<com.ym.mec.biz.dal.dto.StudentVipDouble11Dto>
+     */
+    List<StudentVipDouble11Dto> getStudentDouble11Info(List<Integer> studentIds);
+
+    /**
      * @Author: Joburgess
      * @Date: 2019/9/20
      * 根据学生ID获取学生基本报名信息

+ 24 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentManageServiceImpl.java

@@ -231,6 +231,30 @@ public class StudentManageServiceImpl implements StudentManageService {
     }
 
     @Override
+    public List<StudentVipDouble11Dto> getStudentDouble11Info(List<Integer> studentIds) {
+        List<StudentVipDouble11Dto> studentsDouble11Infos = studentPaymentOrderDao.findStudentsDouble11Infos(studentIds);
+        SysConfig vipSpecialActivityConfig = sysConfigService.findByParamName(SysConfigService.VIP_SPECIAL_ACTIVITY_IDS);
+        Map<Integer, StudentVipDouble11Dto> studentCourseTimeMap = new HashMap<>();
+        if(Objects.nonNull(vipSpecialActivityConfig)&&StringUtils.isNotBlank(vipSpecialActivityConfig.getParanValue())){
+            Set<Integer> specialActivityIds = Arrays.stream(vipSpecialActivityConfig.getParanValue().split(",")).map(Integer::valueOf).collect(Collectors.toSet());
+            List<StudentVipDouble11Dto> studentCourseTimeList = courseScheduleStudentPaymentDao.countStudentDouble11CourseTime(studentIds, new ArrayList<>(specialActivityIds));
+            studentCourseTimeMap = studentCourseTimeList.stream().collect(Collectors.toMap(StudentVipDouble11Dto::getUserId, s -> s));
+        }
+        for (StudentVipDouble11Dto studentVipDouble11Dto : studentsDouble11Infos) {
+            StudentVipDouble11Dto studentCourseTime = studentCourseTimeMap.get(studentVipDouble11Dto.getUserId());
+            studentVipDouble11Dto.setCourseOneToOneTime(studentVipDouble11Dto.getPaymentOneToOneTime()*20-(Objects.isNull(studentCourseTime)?0:studentCourseTime.getCourseOneToOneTime()));
+            if(studentVipDouble11Dto.getCourseOneToOneTime()<0){
+                studentVipDouble11Dto.setCourseOneToOneTime(0);
+            }
+            studentVipDouble11Dto.setCourseOneToTwoTime(studentVipDouble11Dto.getPaymentOneToTwoTime()*20-(Objects.isNull(studentCourseTime)?0:studentCourseTime.getCourseOneToTwoTime()));
+            if(studentVipDouble11Dto.getCourseOneToTwoTime()<0){
+                studentVipDouble11Dto.setCourseOneToTwoTime(0);
+            }
+        }
+        return studentsDouble11Infos;
+    }
+
+    @Override
     public StudentManageListDto findStudentManageBaseInfo(Integer userId) {
         return studentManageDao.findStudentBaseInfoByUserID(userId);
     }

+ 26 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -784,6 +784,7 @@
         GROUP BY
             spo.user_id_
         ORDER BY spo.user_id_
+        <include refid="global.limit" />
     </select>
 
     <select id="countDouble11Students" resultType="int">
@@ -803,4 +804,29 @@
             AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
         </if>;
     </select>
+
+    <select id="findStudentsDouble11Infos" resultMap="StudentVipDouble11Dto">
+        SELECT
+            su.id_ userId,
+            su.username_ userName,
+            su.phone_ phone,
+            su.avatar_ avatar,
+            SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
+            SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
+        FROM
+            student_payment_order spo
+            LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
+            LEFT JOIN student s ON spo.user_id_=s.user_id_
+            LEFT JOIN sys_user su ON spo.user_id_ = su.id_
+        WHERE
+            spo.status_ = 'SUCCESS'
+            AND spo.type_ = 'DOUBLE_ELEVEN2020'
+            AND sci.title_ LIKE '双十一%'
+            AND spo.user_id_ IN
+            <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+                #{studentId}
+            </foreach>
+            GROUP BY
+                spo.user_id_
+    </select>
 </mapper>

+ 42 - 4
mec-teacher/src/main/java/com/ym/mec/teacher/controller/TeacherVipGroupController.java

@@ -3,9 +3,12 @@ package com.ym.mec.teacher.controller;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.TeacherDao;
+import com.ym.mec.biz.dal.dao.VipGroupCategoryDao;
+import com.ym.mec.biz.dal.dto.StudentVipDouble11Dto;
 import com.ym.mec.biz.dal.dto.VipGroupApplyDto;
 import com.ym.mec.biz.dal.dto.VipGroupCostCountParamsDto;
 import com.ym.mec.biz.dal.entity.Teacher;
+import com.ym.mec.biz.dal.entity.VipGroupCategory;
 import com.ym.mec.biz.dal.page.StudentManageQueryInfo;
 import com.ym.mec.biz.service.StudentManageService;
 import com.ym.mec.biz.service.VipGroupService;
@@ -19,11 +22,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -43,6 +45,8 @@ public class TeacherVipGroupController extends BaseController {
 	private TeacherDao teacherDao;
 	@Autowired
 	private StudentManageService studentManageService;
+	@Autowired
+	private VipGroupCategoryDao vipGroupCategoryDao;
 
 	@ApiOperation("vip课申请")
 	@PostMapping("/vipGroupApply")
@@ -78,8 +82,42 @@ public class TeacherVipGroupController extends BaseController {
 		vipGroupApplyDto.getVipGroupApplyBaseInfo().setRegistrationStartTime(new Date());
 		vipGroupApplyDto.getVipGroupApplyBaseInfo().setPaymentExpireDate(DateUtil.addDays(vipGroupApplyDto.getVipGroupApplyBaseInfo().getRegistrationStartTime(),1));
 		vipGroupApplyDto.setOnlyProgress(true);
+
+		VipGroupCategory vipGroupCategory = vipGroupCategoryDao.get(vipGroupApplyDto.getVipGroupApplyBaseInfo().getVipGroupCategoryId());
+		if(Objects.isNull(vipGroupCategory)){
+			return failed("课程形式错误");
+		}
+
+		List<Integer> studentIds = Arrays.stream(vipGroupApplyDto.getVipGroupApplyBaseInfo().getStudentIdList().split(",")).map(Integer::valueOf).collect(Collectors.toList());
+		List<StudentVipDouble11Dto> studentDouble11Info = studentManageService.getStudentDouble11Info(studentIds);
+		Map<Integer, StudentVipDouble11Dto> idStudentInfoMap = new HashMap<>();
+		if(!CollectionUtils.isEmpty(studentDouble11Info)){
+			idStudentInfoMap = studentDouble11Info.stream().collect(Collectors.toMap(StudentVipDouble11Dto::getUserId, s->s, (s1, s2)->s1));
+		}
+		for (Integer studentId : studentIds) {
+			StudentVipDouble11Dto studentVipDouble11Dto = idStudentInfoMap.get(studentId);
+			if(Objects.isNull(studentVipDouble11Dto)){
+				return failed("部分学员可排课次不足");
+			}
+			boolean enableApply = false;
+			switch (vipGroupCategory.getStudentNum()){
+				case 1:
+					enableApply = studentVipDouble11Dto.getCourseOneToOneTime()>=vipGroupApplyDto.getVipGroupApplyBaseInfo().getTotalClassTimes();
+					break;
+				case 2:
+					enableApply = studentVipDouble11Dto.getCourseOneToTwoTime()>=vipGroupApplyDto.getVipGroupApplyBaseInfo().getTotalClassTimes();
+					break;
+				default:
+
+					break;
+			}
+			if(!enableApply){
+				return failed("部分学员可排课次不足");
+			}
+		}
+
 		vipGroupService.createVipGroup(vipGroupApplyDto);
-		vipGroupService.addVipGroupStudents(vipGroupApplyDto.getVipGroupApplyBaseInfo().getId(), Arrays.stream(vipGroupApplyDto.getVipGroupApplyBaseInfo().getStudentIdList().split(",")).map(Integer::valueOf).collect(Collectors.toList()));
+		vipGroupService.addVipGroupStudents(vipGroupApplyDto.getVipGroupApplyBaseInfo().getId(), studentIds);
 		return succeed();
 	}