Browse Source

活动排课

zouxuan 4 years ago
parent
commit
99d67c03ee

+ 15 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/ActivityUserMapperDao.java

@@ -41,4 +41,19 @@ public interface ActivityUserMapperDao extends BaseDAO<Integer, ActivityUserMapp
     * @date 2021/10/14 15:40
     */
     ActivityUserMapper findByStudentId(@Param("groupId") Long groupId, @Param("studentId") Integer studentId);
+
+    /**
+     * @description: 消耗排课资格
+     * @param activityUserMapperIds
+     * @param studentIds
+     * @param type
+     * @param groupId
+     * @return int
+     * @author zx
+     * @date 2021/10/15 15:53
+     */
+    int use(@Param("activityUserMapperIds") String activityUserMapperIds,
+            @Param("studentIds") String studentIds,
+            @Param("type") String type,
+            @Param("groupId") Long groupId);
 }

+ 43 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ActivityUserMapperService.java

@@ -3,6 +3,49 @@ package com.ym.mec.biz.service;
 import com.ym.mec.biz.dal.entity.ActivityUserMapper;
 import com.ym.mec.common.service.BaseService;
 
+import java.util.List;
+
 public interface ActivityUserMapperService extends BaseService<Integer, ActivityUserMapper> {
 
+    /**
+    * @description:
+     * @param activityId
+     * @param studentIds
+     * @param type
+    * @return java.util.List<com.ym.mec.biz.dal.entity.ActivityUserMapper>
+    * @author zx
+    * @date 2021/10/15 15:48
+    */
+    List<ActivityUserMapper> findByStudentIdList(Integer activityId, String studentIds, String type);
+
+    /**
+    * @description: 消耗学员排课资格
+     * @param activityUserMapperIds
+     * @param studentIds
+     * @param type
+    * @return void
+    * @author zx
+    * @date 2021/10/15 15:51
+    */
+    int use(String activityUserMapperIds, String studentIds, String type,Long groupId);
+
+    /**
+    * @description:
+     * @param groupId
+     * @param studentId
+    * @return com.ym.mec.biz.dal.entity.ActivityUserMapper
+    * @author zx
+    * @date 2021/10/15 16:16
+    */
+    ActivityUserMapper findByStudentId(Long groupId, Integer studentId);
+
+    /**
+    * @description: 获取活动购买次数
+     * @param activityId
+     * @param userId
+    * @return int
+    * @author zx
+    * @date 2021/10/15 16:18
+    */
+    int countActivityBuyNum(Integer activityId, Integer userId);
 }

+ 22 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ActivityUserMapperServiceImpl.java

@@ -8,6 +8,8 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, ActivityUserMapper>  implements ActivityUserMapperService {
 	
@@ -18,5 +20,24 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 	public BaseDAO<Integer, ActivityUserMapper> getDAO() {
 		return activityUserMapperDao;
 	}
-	
+
+    @Override
+    public List<ActivityUserMapper> findByStudentIdList(Integer activityId, String studentIds, String type) {
+        return activityUserMapperDao.findByStudentIdList(activityId,studentIds,type);
+    }
+
+	@Override
+	public int use(String activityUserMapperIds, String studentIds, String type,Long groupId) {
+		return activityUserMapperDao.use(activityUserMapperIds,studentIds,type,groupId);
+	}
+
+	@Override
+	public ActivityUserMapper findByStudentId(Long groupId, Integer studentId) {
+		return activityUserMapperDao.findByStudentId(groupId,studentId);
+	}
+
+	@Override
+	public int countActivityBuyNum(Integer activityId, Integer userId) {
+		return activityUserMapperDao.countActivityBuyNum(activityId,userId);
+	}
 }

+ 12 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PracticeGroupServiceImpl.java

@@ -135,7 +135,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
     @Autowired
     private VipGroupActivityDao vipGroupActivityDao;
     @Autowired
-    private ActivityUserMapperDao activityUserMapperDao;
+    private ActivityUserMapperService activityUserMapperService;
     @Autowired
     private MemberFeeSettingDao memberFeeSettingDao;
     @Autowired
@@ -3986,7 +3986,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
                     }
                 }
             }
-            activityUserMapperDao.insert(activityUserMapper);
+            activityUserMapperService.insert(activityUserMapper);
             SysUserCashAccount sysUserCashAccount = sysUserCashAccountService.get(userId);
             //插入缴费明细
             //收入
@@ -4767,10 +4767,11 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         }
         Boolean giveFlag = practice.getGiveFlag();
         //获取学员排课资格
-        List<ActivityUserMapper> activityUserMappers = activityUserMapperDao.findByStudentIdList(activity.getId(),studentId.toString(),giveFlag?"GIVE_PRACTICE":"PRACTICE");
+        List<ActivityUserMapper> activityUserMappers = activityUserMapperService.findByStudentIdList(activity.getId(),studentId.toString(),giveFlag?"GIVE_PRACTICE":"PRACTICE");
         if(activityUserMappers.size() == 0){
             throw new BizException("所选学员暂无排课资格");
         }
+
         Date now = new Date();
 
         //获取第一节课
@@ -4831,6 +4832,12 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         applyBaseInfo.setPaymentExpireDate(DateUtil.getLastSecondWithDay(applyBaseInfo.getPaymentExpireDate()));
 
         practiceGroupDao.insert(applyBaseInfo);
+        //消耗排课资格
+        List<Integer> activityUserMapperIds = activityUserMappers.stream().map(e -> e.getId()).collect(Collectors.toList());
+        int use = activityUserMapperService.use(StringUtils.join(activityUserMapperIds), studentId.toString(), giveFlag ? "GIVE_PRACTICE" : "PRACTICE", applyBaseInfo.getId());
+        if(use != 1){
+            throw new BizException("网管课创建失败,请联系管理员");
+        }
 
         //创建班级信息
         ClassGroup classGroup=new ClassGroup();
@@ -5015,7 +5022,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         }
 
         if(Objects.nonNull(vipGroupActivity) && Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes()) && vipGroupActivity.getStudentMaxUsedTimes() != -1){
-            int useNum = activityUserMapperDao.countActivityBuyNum(vipGroupActivity.getId(),user.getId());
+            int useNum = activityUserMapperService.countActivityBuyNum(vipGroupActivity.getId(),user.getId());
             if(useNum >= vipGroupActivity.getStudentMaxUsedTimes()){
                 throw new BizException("您已超过该活动购买次数限制", vipGroupActivity.getStudentMaxUsedTimes());
             }
@@ -5139,7 +5146,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         Integer studentMaxUsedTimes = activity.getStudentMaxUsedTimes();
         if(studentMaxUsedTimes != -1){
             //获取活动购买次数
-            int activityBuyNum = activityUserMapperDao.countActivityBuyNum(activityId, practiceGroupBuyParams.getUserId());
+            int activityBuyNum = activityUserMapperService.countActivityBuyNum(activityId, practiceGroupBuyParams.getUserId());
             if(activityBuyNum >= studentMaxUsedTimes){
                 throw new BizException("当前活动最多课购买{}次,感谢您的参与",studentMaxUsedTimes);
             }

+ 11 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -155,9 +155,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 	@Autowired
 	private SysCouponCodeService sysCouponCodeService;
 	@Autowired
-	private ActivityUserMapperDao activityUserMapperDao;
-	@Autowired
-	private CloudTeacherOrderDao cloudTeacherOrderDao;
+	private ActivityUserMapperService activityUserMapperService;
 	@Autowired
 	private PracticeGroupService practiceGroupService;
 
@@ -931,7 +929,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		Boolean giveFlag = vipGroup.getGiveFlag();
 		List<Integer> studentIdList = Arrays.stream(studentIds.split(",")).map(id->Integer.valueOf(id)).collect(Collectors.toList());
 		//获取学员排课资格
-		List<ActivityUserMapper> activityUserMappers = activityUserMapperDao.findByStudentIdList(activity.getId(),studentIds,giveFlag?"GIVE_VIP":"VIP");
+		List<ActivityUserMapper> activityUserMappers = activityUserMapperService.findByStudentIdList(activity.getId(),studentIds,giveFlag?"GIVE_VIP":"VIP");
 		if(studentIdList.size() != activityUserMappers.size()){
 			throw new BizException("所选学员暂无排课资格");
 		}
@@ -1038,6 +1036,13 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 
 		vipGroupDao.insert(applyBaseInfo);
 
+		//消耗排课资格
+		List<Integer> activityUserMapperIds = activityUserMappers.stream().map(e -> e.getId()).collect(Collectors.toList());
+		int use = activityUserMapperService.use(StringUtils.join(activityUserMapperIds), studentIds, giveFlag?"GIVE_VIP":"VIP", applyBaseInfo.getId());
+		if(use != studentIdList.size()){
+			throw new BizException("VIP课创建失败,请联系管理员");
+		}
+
 		vscps.forEach(e->e.setVipGroupId(applyBaseInfo.getId()));
 		vipGroupStudentCoursePriceDao.batchInsert(vscps);
 
@@ -3116,7 +3121,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			throw new BizException("学员最大可退费金额为{}元", suplusCourseFee.toString());
 		}
 		//退还活动购买
-		ActivityUserMapper activityUserMapper = activityUserMapperDao.findByStudentId(vipGroup.getId(),studentId);
+		ActivityUserMapper activityUserMapper = activityUserMapperService.findByStudentId(vipGroup.getId(),studentId);
 		if(activityUserMapper != null){
 			HttpResponseResult result = groupClassService.quitActivityGive(activityUserMapper.getId(), returnFeeDto.getConfirmReturnActivityGive(), studentId);
 			if(result.getCode() != 200){
@@ -3564,7 +3569,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		if (studentApplyRefunds.getStatus() == StudentApplyRefundsStatus.DONE) {
 			//退还活动购买
 			VipGroup vipGroup = vipGroupDao.get(id);
-			ActivityUserMapper activityUserMapper = activityUserMapperDao.findByStudentId(vipGroup.getId(), studentPaymentOrder.getUserId());
+			ActivityUserMapper activityUserMapper = activityUserMapperService.findByStudentId(vipGroup.getId(), studentPaymentOrder.getUserId());
 			if(activityUserMapper != null){
 				HttpResponseResult result = groupClassService.quitActivityGive(activityUserMapper.getId(),confirmReturnActivityGive, studentApplyRefunds.getUserId());
 				if(result.getCode() != 200){

+ 19 - 1
mec-biz/src/main/resources/config/mybatis/ActivityUserMapperMapper.xml

@@ -103,7 +103,25 @@
 			update_time_ = NOW()
 		</set>WHERE id_ = #{id}
 	</update>
-	
+	<update id="use">
+		<if test="type == 'VIP'">
+			UPDATE activity_user_mapper SET vip_flag_ = 2,vip_group_id_ = #{groupId},update_time_ = NOW()
+			WHERE FIND_IN_SET(id_,#{activityUserMapperIds}) AND FIND_IN_SET(user_id_,#{studentIds}) AND return_fee_ = 0 AND vip_flag_ = 1;
+		</if>
+		<if test="type == 'GIVE_VIP'">
+			UPDATE activity_user_mapper SET give_vip_flag_ = 2,give_vip_group_id_ = #{groupId},update_time_ = NOW()
+			WHERE FIND_IN_SET(id_,#{activityUserMapperIds}) AND FIND_IN_SET(user_id_,#{studentIds}) AND return_fee_ = 0 AND give_vip_flag_ = 1;
+		</if>
+		<if test="type == 'PRACTICE'">
+			UPDATE activity_user_mapper SET practice_flag_ = 2,practice_group_id_ = #{groupId},update_time_ = NOW()
+			WHERE FIND_IN_SET(id_,#{activityUserMapperIds}) AND FIND_IN_SET(user_id_,#{studentIds}) AND return_fee_ = 0 AND practice_flag_ = 1;
+		</if>
+		<if test="type == 'GIVE_PRACTICE'">
+			UPDATE activity_user_mapper SET give_practice_flag_ = 2,give_practice_group_id_ = #{groupId},update_time_ = NOW()
+			WHERE FIND_IN_SET(id_,#{activityUserMapperIds}) AND FIND_IN_SET(user_id_,#{studentIds}) AND return_fee_ = 0 AND give_practice_flag_ = 1;
+		</if>
+	</update>
+
 	<!-- 根据主键删除一条记录 -->
 	<delete id="delete" >
 		DELETE FROM activity_user_mapper WHERE id_ = #{id}