|
@@ -16,7 +16,6 @@ import com.ym.mec.common.page.WrapperUtil;
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
import com.ym.mec.thirdparty.yqpay.DateUtils;
|
|
import com.ym.mec.thirdparty.yqpay.DateUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
-import org.redisson.api.RedissonClient;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -47,8 +46,53 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
|
|
private SysUserFeignService sysUserFeignService;
|
|
private SysUserFeignService sysUserFeignService;
|
|
@Autowired
|
|
@Autowired
|
|
private TenantCloudCourseRecordService tenantCloudCourseRecordService;
|
|
private TenantCloudCourseRecordService tenantCloudCourseRecordService;
|
|
- @Autowired
|
|
|
|
- private RedissonClient redissonClient;
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 扣除冻结的金额
|
|
|
|
+ *
|
|
|
|
+ * @param courseId 课程id
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void courseDeductAmount(Integer courseId){
|
|
|
|
+ TenantCloudCourseRecord lastRecord = checkLastRecord(courseId);
|
|
|
|
+ //写入流水
|
|
|
|
+ lastRecord.setDeductState(1);
|
|
|
|
+ tenantCloudCourseRecordService.save(lastRecord);
|
|
|
|
+ if (baseMapper.deductAmount(lastRecord.getAmount()) != 1) {
|
|
|
|
+ throw new BizException("解除冻结金额失败!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 恢复/取消 冻结的金额
|
|
|
|
+ *
|
|
|
|
+ * @param courseId 课程id
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void courseRecoverAmount(Integer courseId) {
|
|
|
|
+ TenantCloudCourseRecord lastRecord = checkLastRecord(courseId);
|
|
|
|
+ //写入流水
|
|
|
|
+ lastRecord.setDeductState(2);
|
|
|
|
+ tenantCloudCourseRecordService.save(lastRecord);
|
|
|
|
+ //解除冻结金额,恢复余额
|
|
|
|
+ if (baseMapper.recoverAmount(lastRecord.getAmount()) != 1) {
|
|
|
|
+ throw new BizException("解除冻结金额失败!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private TenantCloudCourseRecord checkLastRecord(Integer courseId) {
|
|
|
|
+ TenantCloudCourseRecord lastRecord = tenantCloudCourseRecordService.queryLastRecord(courseId);
|
|
|
|
+ //判断是否是冻结的状态
|
|
|
|
+ if (Objects.nonNull(lastRecord) && lastRecord.getDeductState() != 0) {
|
|
|
|
+ //只有冻结的才能取消冻结 或者 扣费
|
|
|
|
+ throw new BizException("该课程非线上课!");
|
|
|
|
+ }
|
|
|
|
+ lastRecord.setCreatedBy(getUserId());
|
|
|
|
+ lastRecord.setCreatedTime(new Date());
|
|
|
|
+ return lastRecord;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 排课扣费计算
|
|
* 排课扣费计算
|
|
@@ -57,7 +101,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public void courseDeductionRules(List<CourseSchedule> dto) {
|
|
|
|
|
|
+ public void courseFrozenAmount(List<CourseSchedule> dto) {
|
|
Integer tenantId = TenantContextHolder.getTenantId();
|
|
Integer tenantId = TenantContextHolder.getTenantId();
|
|
|
|
|
|
//校验课程 筛选出线上课
|
|
//校验课程 筛选出线上课
|
|
@@ -76,12 +120,19 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
|
|
Map<String, BigDecimal> rule = getRule(tenantId);
|
|
Map<String, BigDecimal> rule = getRule(tenantId);
|
|
BigDecimal frozenAmount = BigDecimal.ZERO;
|
|
BigDecimal frozenAmount = BigDecimal.ZERO;
|
|
|
|
|
|
- for (CourseSchedule course : dto) {//获取总人数 ,+1是算上老师
|
|
|
|
|
|
+ for (CourseSchedule course : dto) {
|
|
|
|
+ TenantCloudCourseRecord lastRecord = tenantCloudCourseRecordService.queryLastRecord(course.getId().intValue());
|
|
|
|
+ if (Objects.nonNull(lastRecord) && lastRecord.getDeductState() == 0) {
|
|
|
|
+ //该课程id最后一条记录也是冻结状态
|
|
|
|
+ throw new BizException("该课程已是线上课!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取总人数 ,+1是算上老师
|
|
Integer totalPeople = course.getStudentNum() + 1;
|
|
Integer totalPeople = course.getStudentNum() + 1;
|
|
//获取每分钟扣费标准
|
|
//获取每分钟扣费标准
|
|
BigDecimal minutePrice = rule.get(String.valueOf(totalPeople));
|
|
BigDecimal minutePrice = rule.get(String.valueOf(totalPeople));
|
|
if (Objects.isNull(minutePrice)) {
|
|
if (Objects.isNull(minutePrice)) {
|
|
- //实际上是没有这个扣费标准
|
|
|
|
|
|
+ //没有这个扣费标准
|
|
throw new BizException("课程人数已达上限,请联系教务老师!");
|
|
throw new BizException("课程人数已达上限,请联系教务老师!");
|
|
}
|
|
}
|
|
//计算总上课时间
|
|
//计算总上课时间
|
|
@@ -102,7 +153,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
|
|
}
|
|
}
|
|
|
|
|
|
//直接修改余额,利用数据库的规则来防ABA的出现
|
|
//直接修改余额,利用数据库的规则来防ABA的出现
|
|
- if (baseMapper.updateAmount(frozenAmount) != 1) {
|
|
|
|
|
|
+ if (baseMapper.frozenAmount(frozenAmount) != 1) {
|
|
//可能是余额不足
|
|
//可能是余额不足
|
|
throw new BizException("线上课预约火爆,请联系教务老师!");
|
|
throw new BizException("线上课预约火爆,请联系教务老师!");
|
|
}
|
|
}
|