|
|
@@ -3,6 +3,9 @@ package com.fs.company.controller.company;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.ServletUtils;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.framework.security.LoginUser;
|
|
|
import com.fs.framework.service.TokenService;
|
|
|
import com.fs.statis.StatisticsRedisConstant;
|
|
|
@@ -12,7 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.fs.statis.StatisticsRedisConstant.*;
|
|
|
|
|
|
@@ -31,6 +37,11 @@ public class IndexStatisticsController {
|
|
|
@Autowired
|
|
|
private IStatisticsService statisticsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CloudHostProper cloudHostProper;
|
|
|
/**
|
|
|
* 分析概览
|
|
|
*/
|
|
|
@@ -94,12 +105,85 @@ public class IndexStatisticsController {
|
|
|
userType = 0;
|
|
|
}
|
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
- Long companyId = loginUser.getCompany().getCompanyId();
|
|
|
- param.setCompanyId(companyId);
|
|
|
|
|
|
- String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
|
|
|
- List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
- return R.ok().put("data", deaMemberTopTenDTOS);
|
|
|
+ if("四川致医".equals(cloudHostProper.getCompanyName())){
|
|
|
+ Long companyId1 = loginUser.getCompany().getCompanyId();
|
|
|
+ Company company = loginUser.getCompany();
|
|
|
+ param.setCompanyId(companyId1);
|
|
|
+ List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS;
|
|
|
+
|
|
|
+ // 参考watchCourseTopTen方法的处理逻辑
|
|
|
+ if ((param.getCompanyId() == null && param.getDeptId() == null) || (param.getCompanyId() == null && param.getDeptId() == 1)){
|
|
|
+ String key = String.format("%s:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType);
|
|
|
+ watchEndPlayTrendDTOS = redisCache.getCacheObject(key);
|
|
|
+ }else if(param.getCompanyId() != null){
|
|
|
+ String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
|
|
|
+ watchEndPlayTrendDTOS = redisCache.getCacheObject(key);
|
|
|
+ }else{
|
|
|
+ Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
|
|
|
+ List<WatchEndPlayTrendDTO> tempDTOS = new ArrayList<>();
|
|
|
+ for(Long companyId : companyIds){
|
|
|
+ String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,companyId);
|
|
|
+ List<WatchEndPlayTrendDTO> companyData = redisCache.getCacheObject(key);
|
|
|
+ if (companyData != null) {
|
|
|
+ tempDTOS.addAll(companyData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 根据startDate 和 x 分组,合并watchUserCount和completedUserCount 限制最多返回10条记录
|
|
|
+ watchEndPlayTrendDTOS = tempDTOS.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ dto -> dto.getStartDate() + ":" + dto.getX(), // 根据startDate和x分组
|
|
|
+ Collectors.reducing(new WatchEndPlayTrendDTO(), (dto1, dto2) -> {
|
|
|
+ // 合并watchUserCount和completedUserCount
|
|
|
+ WatchEndPlayTrendDTO result = new WatchEndPlayTrendDTO();
|
|
|
+ // 复制分组标识字段
|
|
|
+ if (dto2 != null && dto2.getStartDate() != null) {
|
|
|
+ result.setStartDate(dto2.getStartDate());
|
|
|
+ } else if (dto1 != null) {
|
|
|
+ result.setStartDate(dto1.getStartDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dto2 != null && dto2.getX() != null) {
|
|
|
+ result.setX(dto2.getX());
|
|
|
+ } else if (dto1 != null) {
|
|
|
+ result.setX(dto1.getX());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并数值字段
|
|
|
+ result.setWatchUserCount(
|
|
|
+ (dto1 == null || dto1.getWatchUserCount() == null ? 0 : dto1.getWatchUserCount()) +
|
|
|
+ (dto2 == null || dto2.getWatchUserCount() == null ? 0 : dto2.getWatchUserCount())
|
|
|
+ );
|
|
|
+
|
|
|
+ result.setCompletedUserCount(
|
|
|
+ (dto1 == null || dto1.getCompletedUserCount() == null ? 0 : dto1.getCompletedUserCount()) +
|
|
|
+ (dto2 == null || dto2.getCompletedUserCount() == null ? 0 : dto2.getCompletedUserCount())
|
|
|
+ );
|
|
|
+
|
|
|
+ return result;
|
|
|
+ })
|
|
|
+ ))
|
|
|
+ .values()
|
|
|
+ .stream()
|
|
|
+ .filter(Objects::nonNull) // 过滤掉null值
|
|
|
+ .limit(10)
|
|
|
+ .sorted(Comparator.comparing(WatchEndPlayTrendDTO::getX))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(watchEndPlayTrendDTOS == null){
|
|
|
+ watchEndPlayTrendDTOS = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("data", watchEndPlayTrendDTOS);
|
|
|
+ }else{
|
|
|
+ Long companyId = loginUser.getCompany().getCompanyId();
|
|
|
+ param.setCompanyId(companyId);
|
|
|
+
|
|
|
+ String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
|
|
|
+ List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
|
|
|
+ return R.ok().put("data", deaMemberTopTenDTOS);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|