|
@@ -140,63 +140,73 @@ public class FsUserWatchStatisticsServiceImpl extends ServiceImpl<FsUserWatchSta
|
|
|
|
|
|
//获取公司的会员数量和今日新增会员数量
|
|
|
List<FsUserWatchStatistics> userTotal = fsUserMapper.selectFsUserTotal();
|
|
|
- Map<String, FsUserWatchStatistics> userTotalMap = userTotal.stream().collect(Collectors.toMap(FsUserWatchStatistics::getCompanyId, Function.identity()));
|
|
|
-
|
|
|
- List<FsUserWatchStatistics> list = fsUserCoursePeriods.stream()
|
|
|
- .flatMap(item -> Arrays.stream(item.getCompanyId().split(","))
|
|
|
- .map(companyIdStr -> {
|
|
|
- Long companyId = Long.valueOf(companyIdStr.trim());
|
|
|
- Company company = companyMap.get(companyId);
|
|
|
-
|
|
|
- // 赋值
|
|
|
- FsUserWatchStatistics fsUserWatchStatistics = new FsUserWatchStatistics();
|
|
|
- BeanUtils.copyProperties(item, fsUserWatchStatistics);
|
|
|
- ZonedDateTime zonedDateTime = item.getPeriodStartingTime().atStartOfDay(ZoneId.systemDefault());
|
|
|
- // 改成使用营期线来表示营期开始时间
|
|
|
- fsUserWatchStatistics.setPeriodStartingTime(item.getPeriodLine() != null ? item.getPeriodLine() : Date.from(zonedDateTime.toInstant()));
|
|
|
- fsUserWatchStatistics.setCompanyId(companyIdStr.trim());
|
|
|
- fsUserWatchStatistics.setCompanyName(company != null ? company.getCompanyName() : null);
|
|
|
-
|
|
|
- FsUserWatchStatistics userTotalData = userTotalMap.get(fsUserWatchStatistics.getCompanyId());
|
|
|
-
|
|
|
- String key = String.format("%s-%s", fsUserWatchStatistics.getPeriodId(), fsUserWatchStatistics.getCompanyId());
|
|
|
- FsUserWatchStatistics watchData = courseWatchStatisticsMap.get(key);
|
|
|
-
|
|
|
- if(userTotalData != null){
|
|
|
- fsUserWatchStatistics.setUserNum(userTotalData.getUserNum());
|
|
|
- fsUserWatchStatistics.setNewUserNum(userTotalData.getNewUserNum());
|
|
|
- } else {
|
|
|
- fsUserWatchStatistics.setUserNum(0);
|
|
|
- fsUserWatchStatistics.setNewUserNum(0);
|
|
|
- }
|
|
|
-
|
|
|
- if(watchData != null){
|
|
|
- fsUserWatchStatistics.setWatchNum(watchData.getWatchNum());
|
|
|
- fsUserWatchStatistics.setCompleteWatchNum(watchData.getCompleteWatchNum());
|
|
|
- fsUserWatchStatistics.setCompleteWatchRate(watchData.getCompleteWatchRate());
|
|
|
- } else {
|
|
|
- fsUserWatchStatistics.setWatchNum(0);
|
|
|
- fsUserWatchStatistics.setCompleteWatchNum(0);
|
|
|
- fsUserWatchStatistics.setCompleteWatchRate(BigDecimal.ZERO);
|
|
|
- }
|
|
|
-
|
|
|
- // 计算上线率
|
|
|
- BigDecimal watchNum = new BigDecimal(fsUserWatchStatistics.getWatchNum());
|
|
|
- BigDecimal userNum = new BigDecimal(fsUserWatchStatistics.getUserNum());
|
|
|
- if(!userNum.equals(BigDecimal.ZERO)){
|
|
|
- BigDecimal onlineRate = watchNum.divide(userNum, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
|
|
|
- fsUserWatchStatistics.setOnlineRate(onlineRate);
|
|
|
- } else {
|
|
|
- fsUserWatchStatistics.setOnlineRate(BigDecimal.ZERO);
|
|
|
- }
|
|
|
-
|
|
|
- fsUserWatchStatistics.setCreateTime(new Date());
|
|
|
- fsUserWatchStatistics.setUpdateTime(new Date());
|
|
|
- return fsUserWatchStatistics;
|
|
|
- })).collect(Collectors.toList());
|
|
|
-
|
|
|
- //2、分批次插入数据
|
|
|
- this.batchInsert(list);
|
|
|
+ Map<String, FsUserWatchStatistics> userTotalMap;
|
|
|
+ if (userTotal != null && userTotal.size() > 0) {
|
|
|
+ userTotalMap = userTotal.stream().collect(Collectors.toMap(FsUserWatchStatistics::getCompanyId, Function.identity()));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ userTotalMap = null;
|
|
|
+ }
|
|
|
+ if (!fsUserCoursePeriods.isEmpty()) {
|
|
|
+ List<FsUserWatchStatistics> list = fsUserCoursePeriods.stream()
|
|
|
+ .flatMap(item -> Arrays.stream(item.getCompanyId().split(","))
|
|
|
+ .map(companyIdStr -> {
|
|
|
+ Long companyId = Long.valueOf(companyIdStr.trim());
|
|
|
+ Company company = companyMap.get(companyId);
|
|
|
+
|
|
|
+ // 赋值
|
|
|
+ FsUserWatchStatistics fsUserWatchStatistics = new FsUserWatchStatistics();
|
|
|
+ BeanUtils.copyProperties(item, fsUserWatchStatistics);
|
|
|
+ ZonedDateTime zonedDateTime = item.getPeriodStartingTime().atStartOfDay(ZoneId.systemDefault());
|
|
|
+ // 改成使用营期线来表示营期开始时间
|
|
|
+ fsUserWatchStatistics.setPeriodStartingTime(item.getPeriodLine() != null ? item.getPeriodLine() : Date.from(zonedDateTime.toInstant()));
|
|
|
+ fsUserWatchStatistics.setCompanyId(companyIdStr.trim());
|
|
|
+ fsUserWatchStatistics.setCompanyName(company != null ? company.getCompanyName() : null);
|
|
|
+ if (Objects.nonNull(userTotalMap)){
|
|
|
+ FsUserWatchStatistics userTotalData = userTotalMap.get(fsUserWatchStatistics.getCompanyId());
|
|
|
+ if(userTotalData != null){
|
|
|
+ fsUserWatchStatistics.setUserNum(userTotalData.getUserNum());
|
|
|
+ fsUserWatchStatistics.setNewUserNum(userTotalData.getNewUserNum());
|
|
|
+ } else {
|
|
|
+ fsUserWatchStatistics.setUserNum(0);
|
|
|
+ fsUserWatchStatistics.setNewUserNum(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = String.format("%s-%s", fsUserWatchStatistics.getPeriodId(), fsUserWatchStatistics.getCompanyId());
|
|
|
+ FsUserWatchStatistics watchData = courseWatchStatisticsMap.get(key);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(watchData != null){
|
|
|
+ fsUserWatchStatistics.setWatchNum(watchData.getWatchNum());
|
|
|
+ fsUserWatchStatistics.setCompleteWatchNum(watchData.getCompleteWatchNum());
|
|
|
+ fsUserWatchStatistics.setCompleteWatchRate(watchData.getCompleteWatchRate());
|
|
|
+ } else {
|
|
|
+ fsUserWatchStatistics.setWatchNum(0);
|
|
|
+ fsUserWatchStatistics.setCompleteWatchNum(0);
|
|
|
+ fsUserWatchStatistics.setCompleteWatchRate(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算上线率
|
|
|
+ BigDecimal watchNum = new BigDecimal(fsUserWatchStatistics.getWatchNum());
|
|
|
+ BigDecimal userNum = new BigDecimal(fsUserWatchStatistics.getUserNum());
|
|
|
+ if(!userNum.equals(BigDecimal.ZERO)){
|
|
|
+ BigDecimal onlineRate = watchNum.divide(userNum, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
|
|
|
+ fsUserWatchStatistics.setOnlineRate(onlineRate);
|
|
|
+ } else {
|
|
|
+ fsUserWatchStatistics.setOnlineRate(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ fsUserWatchStatistics.setCreateTime(new Date());
|
|
|
+ fsUserWatchStatistics.setUpdateTime(new Date());
|
|
|
+ return fsUserWatchStatistics;
|
|
|
+ })).collect(Collectors.toList());
|
|
|
+ //2、分批次插入数据
|
|
|
+ this.batchInsert(list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void batchInsert(List<FsUserWatchStatistics> list) {
|