Browse Source

Merge branch 'saas_activity_user_mapper' of http://git.dayaedu.com/yonge/mec into master_saas

zouxuan 3 years ago
parent
commit
9b6ca5ec95

+ 38 - 71
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ActivityStudentDto.java

@@ -1,5 +1,7 @@
 package com.ym.mec.biz.dal.dto;
 package com.ym.mec.biz.dal.dto;
 
 
+import io.swagger.annotations.ApiModelProperty;
+
 public class ActivityStudentDto{
 public class ActivityStudentDto{
 
 
     private String organName;
     private String organName;
@@ -10,21 +12,49 @@ public class ActivityStudentDto{
 
 
     private String phone;
     private String phone;
 
 
-    private Integer freeVipNum;
+    @ApiModelProperty(value = "总付费课时数")
+    private Integer totalCourseNum;
+
+    @ApiModelProperty(value = "剩余付费课时数")
+    private Integer subCourseNum;
+
+    @ApiModelProperty(value = "总赠送课时数")
+    private Integer totalGiveCourseNum;
 
 
-    private Integer useVipNum;
+    @ApiModelProperty(value = "剩余赠送课时数")
+    private Integer subGiveCourseNum;
 
 
-    private Integer freeGiveVipNum;
+    public Integer getTotalCourseNum() {
+        return totalCourseNum;
+    }
 
 
-    private Integer useGiveVipNum;
+    public void setTotalCourseNum(Integer totalCourseNum) {
+        this.totalCourseNum = totalCourseNum;
+    }
 
 
-    private Integer freePracticeNum;
+    public Integer getSubCourseNum() {
+        return subCourseNum;
+    }
 
 
-    private Integer usePracticeNum;
+    public void setSubCourseNum(Integer subCourseNum) {
+        this.subCourseNum = subCourseNum;
+    }
+
+    public Integer getTotalGiveCourseNum() {
+        return totalGiveCourseNum;
+    }
+
+    public void setTotalGiveCourseNum(Integer totalGiveCourseNum) {
+        this.totalGiveCourseNum = totalGiveCourseNum;
+    }
 
 
-    private Integer freeGivePracticeNum;
+    public Integer getSubGiveCourseNum() {
+        return subGiveCourseNum;
+    }
 
 
-    private Integer useGivePracticeNum;
+    public void setSubGiveCourseNum(Integer subGiveCourseNum) {
+        this.subGiveCourseNum = subGiveCourseNum;
+    }
 
 
     public String getOrganName() {
     public String getOrganName() {
         return organName;
         return organName;
@@ -58,67 +88,4 @@ public class ActivityStudentDto{
         this.phone = phone;
         this.phone = phone;
     }
     }
 
 
-    public Integer getFreeVipNum() {
-        return freeVipNum;
-    }
-
-    public void setFreeVipNum(Integer freeVipNum) {
-        this.freeVipNum = freeVipNum;
-    }
-
-    public Integer getUseVipNum() {
-        return useVipNum;
-    }
-
-    public void setUseVipNum(Integer useVipNum) {
-        this.useVipNum = useVipNum;
-    }
-
-    public Integer getFreeGiveVipNum() {
-        return freeGiveVipNum;
-    }
-
-    public void setFreeGiveVipNum(Integer freeGiveVipNum) {
-        this.freeGiveVipNum = freeGiveVipNum;
-    }
-
-    public Integer getUseGiveVipNum() {
-        return useGiveVipNum;
-    }
-
-    public void setUseGiveVipNum(Integer useGiveVipNum) {
-        this.useGiveVipNum = useGiveVipNum;
-    }
-
-    public Integer getFreePracticeNum() {
-        return freePracticeNum;
-    }
-
-    public void setFreePracticeNum(Integer freePracticeNum) {
-        this.freePracticeNum = freePracticeNum;
-    }
-
-    public Integer getUsePracticeNum() {
-        return usePracticeNum;
-    }
-
-    public void setUsePracticeNum(Integer usePracticeNum) {
-        this.usePracticeNum = usePracticeNum;
-    }
-
-    public Integer getFreeGivePracticeNum() {
-        return freeGivePracticeNum;
-    }
-
-    public void setFreeGivePracticeNum(Integer freeGivePracticeNum) {
-        this.freeGivePracticeNum = freeGivePracticeNum;
-    }
-
-    public Integer getUseGivePracticeNum() {
-        return useGivePracticeNum;
-    }
-
-    public void setUseGivePracticeNum(Integer useGivePracticeNum) {
-        this.useGivePracticeNum = useGivePracticeNum;
-    }
 }
 }

+ 3 - 3
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ActivityUserDto.java

@@ -17,7 +17,7 @@ public class ActivityUserDto {
     private String subjectName;
     private String subjectName;
 
 
     @ApiModelProperty(value = "剩余可排课次数")
     @ApiModelProperty(value = "剩余可排课次数")
-    private String subCourseNum;
+    private Integer subCourseNum;
 
 
     public String getPhone() {
     public String getPhone() {
         return phone;
         return phone;
@@ -67,11 +67,11 @@ public class ActivityUserDto {
         this.subjectName = subjectName;
         this.subjectName = subjectName;
     }
     }
 
 
-    public String getSubCourseNum() {
+    public Integer getSubCourseNum() {
         return subCourseNum;
         return subCourseNum;
     }
     }
 
 
-    public void setSubCourseNum(String subCourseNum) {
+    public void setSubCourseNum(Integer subCourseNum) {
         this.subCourseNum = subCourseNum;
         this.subCourseNum = subCourseNum;
     }
     }
 }
 }

+ 3 - 3
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/VipGroupStudentDto.java

@@ -12,7 +12,7 @@ import java.util.Date;
 public class VipGroupStudentDto {
 public class VipGroupStudentDto {
 
 
     @ApiModelProperty(value = "用户编号")
     @ApiModelProperty(value = "用户编号")
-    private Long id;
+    private Integer id;
 
 
     @ApiModelProperty(value = "用户名称")
     @ApiModelProperty(value = "用户名称")
     private String userName;
     private String userName;
@@ -116,11 +116,11 @@ public class VipGroupStudentDto {
         this.phone = phone;
         this.phone = phone;
     }
     }
 
 
-    public Long getId() {
+    public Integer getId() {
         return id;
         return id;
     }
     }
 
 
-    public void setId(Long id) {
+    public void setId(Integer id) {
         this.id = id;
         this.id = id;
     }
     }
 
 

+ 13 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/ActivityUserQueryInfo.java

@@ -2,6 +2,8 @@ package com.ym.mec.biz.dal.page;
 
 
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModelProperty;
 
 
+import java.util.List;
+
 /**
 /**
 * @author zx
 * @author zx
 * @date 2021/9/26 15:52
 * @date 2021/9/26 15:52
@@ -24,6 +26,17 @@ public class ActivityUserQueryInfo{
     @ApiModelProperty(value = "用于模糊查询")
     @ApiModelProperty(value = "用于模糊查询")
     private String search;
     private String search;
 
 
+    @ApiModelProperty(value = "学员列表")
+    private List<Integer> studentIds;
+
+    public List<Integer> getStudentIds() {
+        return studentIds;
+    }
+
+    public void setStudentIds(List<Integer> studentIds) {
+        this.studentIds = studentIds;
+    }
+
     public String getSearch() {
     public String getSearch() {
         return search;
         return search;
     }
     }

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

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service;
 package com.ym.mec.biz.service;
 
 
+import com.ym.mec.biz.dal.dao.ActivityUserMapperDao;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.page.ActivityStudentQueryInfo;
 import com.ym.mec.biz.dal.page.ActivityStudentQueryInfo;
@@ -202,4 +203,8 @@ public interface ActivityUserMapperService extends BaseService<Integer, Activity
     * @date 2022/8/3 13:44
     * @date 2022/8/3 13:44
     */
     */
     void subCourseConvert(List<CourseScheduleStudentPayment> studentPayments, Integer studentId, Integer singleClassMinutes,Integer categoryId);
     void subCourseConvert(List<CourseScheduleStudentPayment> studentPayments, Integer studentId, Integer singleClassMinutes,Integer categoryId);
+
+    ActivityUserMapperDao getDao();
+
+    BigDecimal use(List<ActivityUserMapper> activityUserMappers, List<ActivityUserMapper> freeActivityUserMappers, int j, int a,Long groupId);
 }
 }

+ 60 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ActivityUserMapperServiceImpl.java

@@ -807,14 +807,22 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 			if(StringUtils.isEmpty(activityUserMapper.getVipGroupId())){
 			if(StringUtils.isEmpty(activityUserMapper.getVipGroupId())){
 				activityUserMapper.setVipGroupId(groupId.toString());
 				activityUserMapper.setVipGroupId(groupId.toString());
 			}else {
 			}else {
-				activityUserMapper.setVipGroupId(activityUserMapper.getVipGroupId()+","+groupId);
+				String[] split = activityUserMapper.getVipGroupId().split(",");
+				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
+				if(!idList.contains(groupId.toString())){
+					activityUserMapper.setVipGroupId(activityUserMapper.getVipGroupId()+","+groupId);
+				}
 			}
 			}
 			activityUserMapper.setVipFlag(2);
 			activityUserMapper.setVipFlag(2);
 		}else {
 		}else {
 			if(StringUtils.isEmpty(activityUserMapper.getPracticeGroupId())){
 			if(StringUtils.isEmpty(activityUserMapper.getPracticeGroupId())){
 				activityUserMapper.setPracticeGroupId(groupId.toString());
 				activityUserMapper.setPracticeGroupId(groupId.toString());
 			}else {
 			}else {
-				activityUserMapper.setPracticeGroupId(activityUserMapper.getPracticeGroupId()+","+groupId);
+				String[] split = activityUserMapper.getPracticeGroupId().split(",");
+				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
+				if(!idList.contains(groupId.toString())){
+					activityUserMapper.setPracticeGroupId(activityUserMapper.getPracticeGroupId()+","+groupId);
+				}
 			}
 			}
 			//虽然还有剩余价值,但是这里处理为已排课,不再考虑退费问题
 			//虽然还有剩余价值,但是这里处理为已排课,不再考虑退费问题
 			activityUserMapper.setPracticeFlag(2);
 			activityUserMapper.setPracticeFlag(2);
@@ -825,14 +833,22 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 			if(StringUtils.isEmpty(activityUserMapper.getGiveVipGroupId())){
 			if(StringUtils.isEmpty(activityUserMapper.getGiveVipGroupId())){
 				activityUserMapper.setGiveVipGroupId(groupId.toString());
 				activityUserMapper.setGiveVipGroupId(groupId.toString());
 			}else {
 			}else {
-				activityUserMapper.setGiveVipGroupId(activityUserMapper.getGiveVipGroupId()+","+groupId);
+				String[] split = activityUserMapper.getGiveVipGroupId().split(",");
+				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
+				if(!idList.contains(groupId.toString())){
+					activityUserMapper.setGiveVipGroupId(activityUserMapper.getGiveVipGroupId()+","+groupId);
+				}
 			}
 			}
 			activityUserMapper.setGiveVipFlag(2);
 			activityUserMapper.setGiveVipFlag(2);
 		}else {
 		}else {
 			if(StringUtils.isEmpty(activityUserMapper.getGivePracticeGroupId())){
 			if(StringUtils.isEmpty(activityUserMapper.getGivePracticeGroupId())){
 				activityUserMapper.setGivePracticeGroupId(groupId.toString());
 				activityUserMapper.setGivePracticeGroupId(groupId.toString());
 			}else {
 			}else {
-				activityUserMapper.setGivePracticeGroupId(activityUserMapper.getGivePracticeGroupId()+","+groupId);
+				String[] split = activityUserMapper.getGivePracticeGroupId().split(",");
+				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
+				if(!idList.contains(groupId.toString())){
+					activityUserMapper.setGivePracticeGroupId(activityUserMapper.getGivePracticeGroupId()+","+groupId);
+				}
 			}
 			}
 			//虽然还有剩余价值,但是这里处理为已排课,不再考虑退费问题
 			//虽然还有剩余价值,但是这里处理为已排课,不再考虑退费问题
 			activityUserMapper.setGivePracticeFlag(2);
 			activityUserMapper.setGivePracticeFlag(2);
@@ -1044,4 +1060,44 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 		activityUserMapperDao.insert(activityUserMapper);
 		activityUserMapperDao.insert(activityUserMapper);
 	}
 	}
 
 
+	@Override
+	public ActivityUserMapperDao getDao() {
+		return activityUserMapperDao;
+	}
+
+	@Override
+	public BigDecimal use(List<ActivityUserMapper> activityUserMappers, List<ActivityUserMapper> freeActivityUserMappers, int j, int a,Long groupId) {
+		//扣除排课资格
+		if (!org.springframework.util.CollectionUtils.isEmpty(freeActivityUserMappers) && freeActivityUserMappers.size() > j) {
+			ActivityUserMapper activityUserMapper = freeActivityUserMappers.get(j);
+			Integer subCourseNum = activityUserMapper.getSubCourseNum();
+			if(subCourseNum == 1){
+				j++;
+			}
+			activityUserMapper.setSubCourseNum(subCourseNum - 1);
+			this.modifyGiveGroupId(activityUserMapper,groupId);
+			return ZERO;
+		}else if(!org.springframework.util.CollectionUtils.isEmpty(activityUserMappers) && activityUserMappers.size() > a){
+			ActivityUserMapper activityUserMapper = activityUserMappers.get(a);
+			BigDecimal consumerPrice = ZERO;
+			Integer subCourseNum = activityUserMapper.getSubCourseNum();
+			if(subCourseNum == 1){
+				a++;
+				consumerPrice = activityUserMapper.getSubNoCoursePrice();
+				activityUserMapper.setSubNoCoursePrice(ZERO);
+			}else {
+				if(activityUserMapper.getActualPrice().compareTo(ZERO) > 0) {
+					//单课金额
+					consumerPrice = activityUserMapper.getActualPrice().divide(new BigDecimal(activityUserMapper.getTotalCourseNum()), BigDecimal.ROUND_CEILING, RoundingMode.DOWN);
+					activityUserMapper.setSubNoCoursePrice(activityUserMapper.getSubNoCoursePrice().subtract(consumerPrice));
+				}
+			}
+			activityUserMapper.setSubCourseNum(subCourseNum - 1);
+			this.modifyGroupId(activityUserMapper,groupId);
+			return consumerPrice;
+		}else {
+			throw new BizException("所选学员排课资格不足");
+		}
+	}
+
 }
 }

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

@@ -4350,10 +4350,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
             activityUserMapper.setTenantId(order.getTenantId());
             activityUserMapper.setTenantId(order.getTenantId());
             activityUserMapperService.copyProperty(activityUserMapper,activity,false,true);
             activityUserMapperService.copyProperty(activityUserMapper,activity,false,true);
             if (activity.isPayToBalance()) {
             if (activity.isPayToBalance()) {
-                boolean appendCourseBalance = sysUserCashAccountService.appendCourseBalance(userId, studentPaymentOrder.getExpectAmount(), PlatformCashAccountDetailTypeEnum.RECHARGE, "通用营销活动购买");
-                if (!appendCourseBalance) {
-                    throw new BizException("增加用户课程余额失败");
-                }
+                sysUserCashAccountService.appendCourseBalance(userId, studentPaymentOrder.getExpectAmount(), PlatformCashAccountDetailTypeEnum.RECHARGE, "通用营销活动购买");
             }
             }
             if (activity.getFullMinusCourseTimes() != -1 && order.getActivityBuyNum() >= activity.getFullMinusCourseTimes()) {
             if (activity.getFullMinusCourseTimes() != -1 && order.getActivityBuyNum() >= activity.getFullMinusCourseTimes()) {
                 activityUserMapper.setGiveVipFlag(1);
                 activityUserMapper.setGiveVipFlag(1);

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

@@ -108,10 +108,7 @@ public class SporadicChargeInfoImpl extends BaseServiceImpl<Integer, SporadicCha
                         throw new BizException("给用户增加抽奖次数失败");
                         throw new BizException("给用户增加抽奖次数失败");
                     }
                     }
                 }
                 }
-                boolean appendCourseBalance = sysUserCashAccountService.appendCourseBalance(userId, studentPaymentOrder.getActualAmount(), PlatformCashAccountDetailTypeEnum.SPORADIC, "双11活动");
-                if (!appendCourseBalance) {
-                    throw new BizException("增加用户课程余额失败");
-                }
+                sysUserCashAccountService.appendCourseBalance(userId, studentPaymentOrder.getActualAmount(), PlatformCashAccountDetailTypeEnum.SPORADIC, "双11活动");
             } else if (info.getChargeType().getCode() == 9 || info.getChargeType().getCode() == 13 || info.getChargeType().getCode() == 14) { //零星收费账户充值,网基课活动,关心包
             } else if (info.getChargeType().getCode() == 9 || info.getChargeType().getCode() == 13 || info.getChargeType().getCode() == 14) { //零星收费账户充值,网基课活动,关心包
                 sysUserCashAccountService.updateBalance(userId, studentPaymentOrder.getActualAmount(), PlatformCashAccountDetailTypeEnum.RECHARGE, "零星收费"+info.getChargeType().getMsg(), studentPaymentOrder.getTransNo());
                 sysUserCashAccountService.updateBalance(userId, studentPaymentOrder.getActualAmount(), PlatformCashAccountDetailTypeEnum.RECHARGE, "零星收费"+info.getChargeType().getMsg(), studentPaymentOrder.getTransNo());
             } else if (info.getOrganId().equals(42) && info.getChargeType().equals(SporadicChargeTypeEnum.LEVEL)) {
             } else if (info.getOrganId().equals(42) && info.getChargeType().equals(SporadicChargeTypeEnum.LEVEL)) {

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

@@ -216,7 +216,7 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
     }
     }
 
 
     @Override
     @Override
-    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
     public boolean appendCourseBalance(Integer userId, BigDecimal decimal, PlatformCashAccountDetailTypeEnum type, String description) {
     public boolean appendCourseBalance(Integer userId, BigDecimal decimal, PlatformCashAccountDetailTypeEnum type, String description) {
         SysUserCashAccount cashAccount = sysUserCashAccountDao.getLocked(userId);
         SysUserCashAccount cashAccount = sysUserCashAccountDao.getLocked(userId);
         if (cashAccount == null) {
         if (cashAccount == null) {

+ 48 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1665,7 +1665,21 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
             if (!CollectionUtils.isEmpty(vipGroupStudentCoursePrices)) {
             if (!CollectionUtils.isEmpty(vipGroupStudentCoursePrices)) {
                 userPriceMap = vipGroupStudentCoursePrices.stream().collect(Collectors.toMap(VipGroupStudentCoursePrice::getStudentId, v -> v, (v1, v2) -> v1));
                 userPriceMap = vipGroupStudentCoursePrices.stream().collect(Collectors.toMap(VipGroupStudentCoursePrice::getStudentId, v -> v, (v1, v2) -> v1));
             }
             }
+            VipGroup vipGroup = vipGroupDao.get(queryInfo.getVipGroupId());
+            List<Integer> studentIds = dataList.stream().map(e -> e.getId()).collect(Collectors.toList());
+            ActivityUserQueryInfo activityUserQueryInfo = new ActivityUserQueryInfo();
+            activityUserQueryInfo.setCategoryId(vipGroup.getVipGroupCategoryId());
+            activityUserQueryInfo.setOrganIds(queryInfo.getOrganId());
+            activityUserQueryInfo.setSingleCourseTime(vipGroup.getSingleClassMinutes());
+            activityUserQueryInfo.setStudentIds(studentIds);
+            List<ActivityUserDto> activityUserDtos = activityUserMapperService.queryActivityStudentList(activityUserQueryInfo);
+            Map<Integer, Integer> collect = new HashMap<>();
+            if(!CollectionUtils.isEmpty(activityUserDtos)){
+                collect = activityUserDtos.stream().
+                        collect(Collectors.groupingBy(ActivityUserDto::getUserId, Collectors.collectingAndThen(Collectors.toList(), value -> value.get(0).getSubCourseNum())));
+            }
             for (VipGroupStudentDto vipGroupStudentDto : dataList) {
             for (VipGroupStudentDto vipGroupStudentDto : dataList) {
+                vipGroupStudentDto.setTotalClassTimes(collect.get(vipGroupStudentDto.getId()));
                 if (!userPriceMap.containsKey(Integer.valueOf(vipGroupStudentDto.getId().toString()))) {
                 if (!userPriceMap.containsKey(Integer.valueOf(vipGroupStudentDto.getId().toString()))) {
                     continue;
                     continue;
                 }
                 }
@@ -3050,15 +3064,38 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
         }
         }
 
 
         List<CourseScheduleStudentPayment> courseScheduleStudentPaymentList = new ArrayList<>();
         List<CourseScheduleStudentPayment> courseScheduleStudentPaymentList = new ArrayList<>();
+        //获取账户信息
+        SysUserCashAccount cashAccount = sysUserCashAccountService.getLocked(studentRecoverInfo.getUserId());
+        if (cashAccount == null) {
+            throw new BizException("用户[{}]现金账户不存在", studentRecoverInfo.getUserId());
+        }
+        BigDecimal courseBalance = cashAccount.getCourseBalance();
+        //获取学员排课资格
+        List studentIdList = new ArrayList<>();
+        studentIdList.add(studentRecoverInfo.getUserId());
+        //获取学员付费排课资格
+        List<ActivityUserMapper> activityUserMappers = activityUserMapperService.getDao().findByStudents(studentIdList,vipGroup.getVipGroupCategoryId(),vipGroup.getSingleClassMinutes());
+        //获取学员赠送排课资格
+        List<ActivityUserMapper> freeActivityUserMappers = activityUserMapperService.getDao().findByStudents1(studentIdList,vipGroup.getVipGroupCategoryId(),vipGroup.getSingleClassMinutes());
+        int j = 0;
+        int a = 0;
         for (int i = 0; i < surplusCourseWithGroup.size(); i++) {
         for (int i = 0; i < surplusCourseWithGroup.size(); i++) {
             CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
             CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
+            BigDecimal actualPrice = coursePrices.get(i);
+            courseScheduleStudentPayment.setExpectPrice(actualPrice);
+            //按课扣除课程余额
+            if(courseBalance.compareTo(actualPrice) >= 0){
+                courseBalance = courseBalance.subtract(actualPrice);
+            }else {
+                //扣除排课资格
+                actualPrice = activityUserMapperService.use(activityUserMappers,freeActivityUserMappers,j,a,vipGroup.getId());
+            }
+            courseScheduleStudentPayment.setActualPrice(actualPrice);
             courseScheduleStudentPayment.setGroupType(GroupType.VIP);
             courseScheduleStudentPayment.setGroupType(GroupType.VIP);
             courseScheduleStudentPayment.setMusicGroupId(studentRecoverInfo.getVipGroupId().toString());
             courseScheduleStudentPayment.setMusicGroupId(studentRecoverInfo.getVipGroupId().toString());
             courseScheduleStudentPayment.setMusicGroupId(classGroup.getMusicGroupId());
             courseScheduleStudentPayment.setMusicGroupId(classGroup.getMusicGroupId());
             courseScheduleStudentPayment.setCourseScheduleId(surplusCourseWithGroup.get(i).getId());
             courseScheduleStudentPayment.setCourseScheduleId(surplusCourseWithGroup.get(i).getId());
             courseScheduleStudentPayment.setUserId(studentRecoverInfo.getUserId());
             courseScheduleStudentPayment.setUserId(studentRecoverInfo.getUserId());
-            courseScheduleStudentPayment.setExpectPrice(coursePrices.get(i));
-            courseScheduleStudentPayment.setActualPrice(coursePrices.get(i));
             courseScheduleStudentPayment.setOriginalPrice(TeachModeEnum.ONLINE.equals(surplusCourseWithGroup.get(i)) ? vipGroupDefaultClassesUnitPrice.getOnlineClassesUnitPrice() : vipGroupDefaultClassesUnitPrice.getOfflineClassesUnitPrice());
             courseScheduleStudentPayment.setOriginalPrice(TeachModeEnum.ONLINE.equals(surplusCourseWithGroup.get(i)) ? vipGroupDefaultClassesUnitPrice.getOnlineClassesUnitPrice() : vipGroupDefaultClassesUnitPrice.getOfflineClassesUnitPrice());
             courseScheduleStudentPayment.setCreateTime(now);
             courseScheduleStudentPayment.setCreateTime(now);
             courseScheduleStudentPayment.setUpdateTime(now);
             courseScheduleStudentPayment.setUpdateTime(now);
@@ -3070,7 +3107,15 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
             studentDao.updateStudentServiceTag(studentRecoverInfo.getUserId(), null, YesOrNoEnum.YES.getCode());
             studentDao.updateStudentServiceTag(studentRecoverInfo.getUserId(), null, YesOrNoEnum.YES.getCode());
             courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPaymentList);
             courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPaymentList);
         }
         }
-        sysUserCashAccountService.appendCourseBalance(studentRecoverInfo.getUserId(), surplusCourseFee.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "学生复学扣除课程余额");
+        //扣余额,如果余额不足,那么扣排课资格
+        if(cashAccount.getCourseBalance().compareTo(courseBalance) != 0){
+            sysUserCashAccountService.appendCourseBalance(studentRecoverInfo.getUserId(), cashAccount.getCourseBalance().subtract(courseBalance).negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "学生复学扣除课程余额");
+        }
+        //更新资格
+        activityUserMappers.addAll(freeActivityUserMappers);
+        if(!CollectionUtils.isEmpty(activityUserMappers)){
+            activityUserMapperService.getDao().batchUpdate(activityUserMappers);
+        }
         studentPauseInfo.setDelFlag(1);
         studentPauseInfo.setDelFlag(1);
         studentPauseInfoDao.update(studentPauseInfo);
         studentPauseInfoDao.update(studentPauseInfo);
         vipGroup.setStatus(VipGroupStatusEnum.PROGRESS);
         vipGroup.setStatus(VipGroupStatusEnum.PROGRESS);
@@ -3744,11 +3789,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
             }
             }
         }
         }
 
 
-//		VipGroupDefaultClassesUnitPrice vipGroupDefaultClassesUnitPrice = vipGroupDefaultClassesUnitPriceDao.getByVipGroup(vipGroup.getId());
-//		if(Objects.isNull(vipGroupDefaultClassesUnitPrice)){
-//			throw new BizException("课程单价设置错误");
-//		}
-
         if (VipGroupStatusEnum.PAUSE.equals(vipGroup.getStatus())
         if (VipGroupStatusEnum.PAUSE.equals(vipGroup.getStatus())
                 || VipGroupStatusEnum.FINISHED.equals(vipGroup.getStatus())
                 || VipGroupStatusEnum.FINISHED.equals(vipGroup.getStatus())
                 || VipGroupStatusEnum.CANCEL.equals(vipGroup.getStatus())) {
                 || VipGroupStatusEnum.CANCEL.equals(vipGroup.getStatus())) {

+ 15 - 16
mec-biz/src/main/resources/config/mybatis/ActivityUserMapperMapper.xml

@@ -326,25 +326,17 @@
 		<result property="username" column="username_"/>
 		<result property="username" column="username_"/>
 		<result property="organName" column="name_"/>
 		<result property="organName" column="name_"/>
 		<result property="phone" column="phone_"/>
 		<result property="phone" column="phone_"/>
-		<result property="freeVipNum" column="free_vip_num_"/>
-		<result property="useVipNum" column="use_vip_num_"/>
-		<result property="freeGiveVipNum" column="free_give_vip_num_"/>
-		<result property="useGiveVipNum" column="use_give_vip_num_"/>
-		<result property="freePracticeNum" column="free_practice_num_"/>
-		<result property="usePracticeNum" column="use_practice_num_"/>
-		<result property="freeGivePracticeNum" column="free_give_practice_num_"/>
-		<result property="useGivePracticeNum" column="use_give_practice_num_"/>
+		<result property="totalCourseNum" column="total_course_num_"/>
+		<result property="subCourseNum" column="sub_course_num_"/>
+		<result property="totalGiveCourseNum" column="total_give_course_num_"/>
+		<result property="subGiveCourseNum" column="sub_give_course_num_"/>
 	</resultMap>
 	</resultMap>
 	<select id="queryActivityUserMapper" resultMap="ActivityStudentDto">
 	<select id="queryActivityUserMapper" resultMap="ActivityStudentDto">
 		SELECT o.name_,aum.user_id_,su.username_,su.phone_,
 		SELECT o.name_,aum.user_id_,su.username_,su.phone_,
-		COUNT(CASE WHEN aum.vip_flag_ = 1 THEN 1 ELSE NULL END) free_vip_num_,
-		COUNT(CASE WHEN aum.vip_flag_ = 2 THEN 1 ELSE NULL END) use_vip_num_,
-		COUNT(CASE WHEN aum.give_vip_flag_ = 1 THEN 1 ELSE NULL END) free_give_vip_num_,
-		COUNT(CASE WHEN aum.give_vip_flag_ = 2 THEN 1 ELSE NULL END) use_give_vip_num_,
-		COUNT(CASE WHEN aum.practice_flag_ = 1 THEN 1 ELSE NULL END) free_practice_num_,
-		COUNT(CASE WHEN aum.practice_flag_ = 2 THEN 1 ELSE NULL END) use_practice_num_,
-		COUNT(CASE WHEN aum.give_practice_flag_ = 1 THEN 1 ELSE NULL END) free_give_practice_num_,
-		COUNT(CASE WHEN aum.give_practice_flag_ = 2 THEN 1 ELSE NULL END) use_give_practice_num_
+		SUM(aum.total_course_num_) total_course_num_,
+		SUM(aum.sub_course_num_) sub_course_num_,
+		SUM(aum.total_give_course_num_) total_give_course_num_,
+		SUM(aum.sub_give_course_num_) sub_give_course_num_
 		FROM activity_user_mapper aum
 		FROM activity_user_mapper aum
 		LEFT JOIN sys_user su ON su.id_ = aum.user_id_
 		LEFT JOIN sys_user su ON su.id_ = aum.user_id_
 		LEFT JOIN organization o ON o.id_ = su.organ_id_
 		LEFT JOIN organization o ON o.id_ = su.organ_id_
@@ -465,6 +457,12 @@
 			<if test="queryInfo.teacherId != null">
 			<if test="queryInfo.teacherId != null">
 				AND aum.teacher_id_ = #{queryInfo.teacherId}
 				AND aum.teacher_id_ = #{queryInfo.teacherId}
 			</if>
 			</if>
+			<if test="queryInfo.studentIds != null and queryInfo.studentIds.size > 0">
+				AND aum.user_id_ IN
+				<foreach collection="queryInfo.studentIds" item="studentId" open="(" separator="," close=")">
+					#{studentId}
+				</foreach>
+			</if>
 		</where>
 		</where>
 		GROUP BY aum.user_id_
 		GROUP BY aum.user_id_
 		ORDER BY sj.id_ DESC,sub_course_num_ DESC
 		ORDER BY sj.id_ DESC,sub_course_num_ DESC
@@ -531,6 +529,7 @@
 		<if test="categoryId == null">
 		<if test="categoryId == null">
 			AND aum.give_category_id_ IS NULL
 			AND aum.give_category_id_ IS NULL
 		</if>
 		</if>
+
 	</select>
 	</select>
 	<select id="findByStudents" resultMap="ActivityUserMapper">
 	<select id="findByStudents" resultMap="ActivityUserMapper">
 		select * from activity_user_mapper aum
 		select * from activity_user_mapper aum