|
@@ -813,12 +813,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
|
|
|
// 处理 UUID 为空的情况
|
|
|
if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
|
|
|
- // 直接插入或更新
|
|
|
-// logger.error("zyp \n【插入或更新流量】:{}",trafficLog);
|
|
|
+ // 插入或更新
|
|
|
fsCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog);
|
|
|
- if(trafficLog.getLogId() != null)
|
|
|
- //扣除流量
|
|
|
- asyncDeductTraffic(company, roundedResult/1024);
|
|
|
+ asyncDeductTraffic(company, trafficLog);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -829,11 +826,21 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
- @Async
|
|
|
- public void asyncDeductTraffic(Company company, Long traffic) {
|
|
|
+ public void asyncDeductTraffic(Company company, FsCourseTrafficLog trafficLog) {
|
|
|
try {
|
|
|
+ //根据uuid查询
|
|
|
+ FsCourseTrafficLog existingLog = fsCourseTrafficLogMapper.selectFsCourseTrafficLogByuuId(trafficLog.getUuId());
|
|
|
+ long recordedTraffic;
|
|
|
+ if (existingLog != null) {
|
|
|
+ recordedTraffic = trafficLog.getInternetTraffic() - existingLog.getInternetTraffic();
|
|
|
+ }else{
|
|
|
+ recordedTraffic = trafficLog.getInternetTraffic();
|
|
|
+ }
|
|
|
+ if (recordedTraffic <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 扣除流量
|
|
|
- Long remainingTraffic = updateRedisCache(company, traffic);
|
|
|
+ Long remainingTraffic = updateRedisCache(company, recordedTraffic/1024);
|
|
|
|
|
|
if ("1".equals(configUtil.generateConfigByKey("watch.course.config").getString("doNotPlay")) && remainingTraffic <= 0) {
|
|
|
logger.warn("公司ID: {} 流量不足,当前剩余: {}", company.getCompanyId(), remainingTraffic);
|
|
@@ -843,8 +850,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
/*logger.info("异步扣除流量成功 - 公司ID: {}, 扣除流量: {}, 剩余流量: {}",
|
|
|
company.getCompanyId(), traffic, remainingTraffic);*/
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("异步扣除流量失败 - 公司ID: {}, 扣除流量: {}, 错误信息: {}",
|
|
|
- company.getCompanyId(), traffic, e.getMessage(), e);
|
|
|
+ logger.error("异步扣除流量失败 - 公司ID: {}, 错误信息: {}",
|
|
|
+ company.getCompanyId(), e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -859,8 +866,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
String deptDayKey = deptKey + ":"+ LocalDate.now();
|
|
|
String deptMonthKey = deptKey + ":"+ YearMonth.now();
|
|
|
|
|
|
- String dayKey = CompanyTrafficConstants.CACHE_KEY+ ":1:"+ LocalDate.now();
|
|
|
- String monthKey = CompanyTrafficConstants.CACHE_KEY+ ":1:"+ YearMonth.now();
|
|
|
String lockKey = companyKey + ":lock";
|
|
|
//销售公司剩余流量
|
|
|
Object companyTraffic = redisCache.getCacheObject(companyKey);
|
|
@@ -874,20 +879,15 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}else{
|
|
|
throw new IllegalArgumentException("流量转换异常");
|
|
|
}
|
|
|
- if(balance<0){
|
|
|
- return balance;
|
|
|
- }
|
|
|
try {
|
|
|
- if (redisCache.setIfAbsent(lockKey, "1", 3, TimeUnit.SECONDS)) {
|
|
|
+ if (redisCache.setIfAbsent(lockKey, "1", 2, TimeUnit.SECONDS)) {
|
|
|
try {
|
|
|
balance = redisCache.decr(companyKey, traffic);
|
|
|
redisCache.decr(deptKey, traffic);
|
|
|
redisCache.incr(companyDayKey, traffic);
|
|
|
redisCache.incr(deptDayKey, traffic);
|
|
|
- redisCache.incr(dayKey, traffic);
|
|
|
redisCache.incr(companyMonthKey, traffic);
|
|
|
redisCache.incr(deptMonthKey, traffic);
|
|
|
- redisCache.incr(monthKey, traffic);
|
|
|
} finally {
|
|
|
redisCache.deleteObject(lockKey); // 释放锁
|
|
|
}
|
|
@@ -2702,11 +2702,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
// 处理 UUID 为空的情况
|
|
|
if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
|
|
|
- // 直接插入或更新
|
|
|
-// logger.error("zyp \n【插入或更新流量】:{}",trafficLog);
|
|
|
+ // 插入或更新
|
|
|
fsCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog);
|
|
|
- if(trafficLog.getLogId() != null)
|
|
|
- asyncDeductTraffic(company, roundedResult/1024);
|
|
|
+ asyncDeductTraffic(company, trafficLog);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|